﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
using System.Text;

using CE.User;
using CE.Global;
using CE.CarInsurance;
using CE.Mail;
using CE.Database;
using CE.InputOut;

public partial class car_insurance_car_insurance_request : System.Web.UI.Page
{
    CE.User.Profile _profile = null;
    CE.User.ProfileDB _profiledb = null;
    Contact _contact = null;
    ContactDB _contactdb = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            LoadNoMatchCoverType(10);

            usrDOB.StartYear = CE.Global.General.GetUTCDateTime().Year - 75;
            usrDOB.EndYear = CE.Global.General.GetUTCDateTime().Year - 18;

            usrDriver1DOB.StartYear = CE.Global.General.GetUTCDateTime().Year - 75;
            usrDriver1DOB.EndYear = CE.Global.General.GetUTCDateTime().Year - 18;

            usrDriver2DOB.StartYear = CE.Global.General.GetUTCDateTime().Year - 75;
            usrDriver2DOB.EndYear = CE.Global.General.GetUTCDateTime().Year - 18;

            usrDriver3DOB.StartYear = CE.Global.General.GetUTCDateTime().Year - 75;
            usrDriver3DOB.EndYear = CE.Global.General.GetUTCDateTime().Year - 18;

            usrDrivingLicenseDate.StartYear = CE.Global.General.GetUTCDateTime().Year - 70;
            usrDrivingLicenseDate.EndYear = CE.Global.General.GetUTCDateTime().Year;

            usrDriver1LicensePassDate.StartYear = CE.Global.General.GetUTCDateTime().Year - 70;
            usrDriver1LicensePassDate.EndYear = CE.Global.General.GetUTCDateTime().Year;

            usrDriver2LicensePassDate.StartYear = CE.Global.General.GetUTCDateTime().Year - 70;
            usrDriver2LicensePassDate.EndYear = CE.Global.General.GetUTCDateTime().Year;

            usrDriver3LicensePassDate.StartYear = CE.Global.General.GetUTCDateTime().Year - 70;
            usrDriver3LicensePassDate.EndYear = CE.Global.General.GetUTCDateTime().Year;

            usrClaim1AccidentDate.StartYear = CE.Global.General.GetUTCDateTime().Year - 3;
            usrClaim1AccidentDate.EndYear = CE.Global.General.GetUTCDateTime().Year;

            usrClaim2AccidentDate.StartYear = CE.Global.General.GetUTCDateTime().Year - 3;
            usrClaim2AccidentDate.EndYear = CE.Global.General.GetUTCDateTime().Year;

            usrClaim3AccidentDate.StartYear = CE.Global.General.GetUTCDateTime().Year - 3;
            usrClaim3AccidentDate.EndYear = CE.Global.General.GetUTCDateTime().Year;

            usrClaim4AccidentDate.StartYear = CE.Global.General.GetUTCDateTime().Year - 3;
            usrClaim4AccidentDate.EndYear = CE.Global.General.GetUTCDateTime().Year;

            usrClaim5AccidentDate.StartYear = CE.Global.General.GetUTCDateTime().Year - 3;
            usrClaim5AccidentDate.EndYear = CE.Global.General.GetUTCDateTime().Year;

            DataTable dtCarMake = General.GetComboItem("CarMake", " [Description]", true);
            ddlCarMake.DataSource = dtCarMake;
            ddlCarMake.DataTextField = dtCarMake.Columns[0].ColumnName.ToString();
            ddlCarMake.DataValueField = dtCarMake.Columns[1].ColumnName.ToString();
            ddlCarMake.DataBind();
            ddlCarMake.Items.Insert(0, new ListItem("Select", "-1"));
            dtCarMake = null;

            ddlNoOfClaim_SelectedIndexChanged(sender, e);
            ddlDriverCount_SelectedIndexChanged(sender, e);

            DateTime dtNow = new DateTime();
            dtNow = CE.Global.General.GetUTCDateTime();
            for (int i = 0; i < 61; i++)
            {
                DateTime dtTemp = dtNow.AddDays(i);
                string strDate = dtTemp.Date.Day.ToString("00") + dtTemp.Date.Month.ToString("00") + dtTemp.Date.Year.ToString("0000");
                ddlCoverageComDate.Items.Add(new ListItem(dtTemp.ToString("dd/MMMM/yyyy"), strDate));
            }
            ddlCoverageComDate.Items.Insert(0, new ListItem("Select", "-1"));

            int _startYear = CE.Global.General.GetUTCDateTime().Year - 20;
            int _endYear = CE.Global.General.GetUTCDateTime().Year;
            for (int i = _endYear; i >= _startYear; i--)
            {
                ddlManYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
                ddlRegYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }

            ddlManYear.Items.Insert(0, new ListItem("Select", "-1"));
            ddlRegYear.Items.Insert(0, new ListItem("Select", "-1"));

            DataTable dtOccupation = General.GetComboItem("Occupation", false);
            ddlOccupation.DataSource = dtOccupation;
            ddlOccupation.DataTextField = dtOccupation.Columns[0].ColumnName.ToString();
            ddlOccupation.DataValueField = dtOccupation.Columns[1].ColumnName.ToString();
            ddlOccupation.DataBind();
            ddlOccupation.Items.Insert(0, new ListItem("Select", "-1"));

            ddlDriver1Occupation.DataSource = dtOccupation;
            ddlDriver1Occupation.DataTextField = dtOccupation.Columns[0].ColumnName.ToString();
            ddlDriver1Occupation.DataValueField = dtOccupation.Columns[1].ColumnName.ToString();
            ddlDriver1Occupation.DataBind();
            ddlDriver1Occupation.Items.Insert(0, new ListItem("Select", "-1"));

            ddlDriver2Occupation.DataSource = dtOccupation;
            ddlDriver2Occupation.DataTextField = dtOccupation.Columns[0].ColumnName.ToString();
            ddlDriver2Occupation.DataValueField = dtOccupation.Columns[1].ColumnName.ToString();
            ddlDriver2Occupation.DataBind();
            ddlDriver2Occupation.Items.Insert(0, new ListItem("Select", "-1"));

            ddlDriver3Occupation.DataSource = dtOccupation;
            ddlDriver3Occupation.DataTextField = dtOccupation.Columns[0].ColumnName.ToString();
            ddlDriver3Occupation.DataValueField = dtOccupation.Columns[1].ColumnName.ToString();
            ddlDriver3Occupation.DataBind();
            ddlDriver3Occupation.Items.Insert(0, new ListItem("Select", "-1"));

            DataTable dtMaritalStatus = General.GetComboItem("MaritalStatus", true);
            ddlMaritalStatus.DataSource = dtMaritalStatus;
            ddlMaritalStatus.DataTextField = dtMaritalStatus.Columns[0].ColumnName.ToString();
            ddlMaritalStatus.DataValueField = dtMaritalStatus.Columns[1].ColumnName.ToString();
            ddlMaritalStatus.DataBind();
            ddlMaritalStatus.Items.Insert(0, new ListItem("Select", "-1"));

            ddlDriver1MaritalStatus.DataSource = dtMaritalStatus;
            ddlDriver1MaritalStatus.DataTextField = dtMaritalStatus.Columns[0].ColumnName.ToString();
            ddlDriver1MaritalStatus.DataValueField = dtMaritalStatus.Columns[1].ColumnName.ToString();
            ddlDriver1MaritalStatus.DataBind();
            ddlDriver1MaritalStatus.Items.Insert(0, new ListItem("Select", "-1"));

            ddlDriver2MaritalStatus.DataSource = dtMaritalStatus;
            ddlDriver2MaritalStatus.DataTextField = dtMaritalStatus.Columns[0].ColumnName.ToString();
            ddlDriver2MaritalStatus.DataValueField = dtMaritalStatus.Columns[1].ColumnName.ToString();
            ddlDriver2MaritalStatus.DataBind();
            ddlDriver2MaritalStatus.Items.Insert(0, new ListItem("Select", "-1"));

            ddlDriver3MaritalStatus.DataSource = dtMaritalStatus;
            ddlDriver3MaritalStatus.DataTextField = dtMaritalStatus.Columns[0].ColumnName.ToString();
            ddlDriver3MaritalStatus.DataValueField = dtMaritalStatus.Columns[1].ColumnName.ToString();
            ddlDriver3MaritalStatus.DataBind();
            ddlDriver3MaritalStatus.Items.Insert(0, new ListItem("Select", "-1"));

            DataTable dtNationality = General.GetComboItem("Nationality", false);
            ddlNationality.DataSource = dtNationality;
            ddlNationality.DataTextField = dtNationality.Columns[0].ColumnName.ToString();
            ddlNationality.DataValueField = dtNationality.Columns[1].ColumnName.ToString();
            ddlNationality.DataBind();
            ddlNationality.Items.Insert(0, new ListItem("Select", "-1"));

            DataTable dtDrivingExpYear = General.GetComboItem("CarYearDriveSg", "[YearDriveSgId]", true);
            ddlDrivingExpYear.DataSource = dtDrivingExpYear;
            ddlDrivingExpYear.DataTextField = dtDrivingExpYear.Columns[0].ColumnName.ToString();
            ddlDrivingExpYear.DataValueField = dtDrivingExpYear.Columns[1].ColumnName.ToString();
            ddlDrivingExpYear.DataBind();
            ddlDrivingExpYear.Items.Insert(0, new ListItem("Select", "-1"));

            CE.Provider.InsurerDB _insurerdb = new CE.Provider.InsurerDB();
            DataTable dtPreInsurerComp = _insurerdb.GetPreInsurer(100, 1);
            ddlCurrentInsurer.DataSource = dtPreInsurerComp;
            ddlCurrentInsurer.DataTextField = dtPreInsurerComp.Columns[0].ColumnName.ToString();
            ddlCurrentInsurer.DataValueField = dtPreInsurerComp.Columns[1].ColumnName.ToString();
            ddlCurrentInsurer.DataBind();
            ddlCurrentInsurer.Items.Insert(0, new ListItem("Select", "-1"));

            Int64 _userId = 0;

            if (Session[General.UserId] != null)
            {
                _userId = Convert.ToInt64(Session[General.UserId].ToString());

                if (Convert.ToInt32(Session[CE.Global.General.UserTypeId]) ==
                Convert.ToInt32(CE.Global.CEUserType.Customer))
                {
                    ShowCustomerDetail(_userId);
                    spanExistingUser.Visible = false;
                }
            }
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            Account _useraccount = new Account();
            AccountDB _useraccountdb = new AccountDB();

            lblAutoLoginStatus.Text = "0";

            if (_useraccountdb.IsAlreadyExist(txtEmailAddress.Text.Trim(), Convert.ToInt32(CE.Global.CEUserType.Customer)))
            {
                _useraccount = _useraccountdb.GetUserAccount(txtEmailAddress.Text.Trim(), Convert.ToInt32(CE.Global.CEUserType.Customer));
                ProfileDB _profiledb = new ProfileDB();
                Profile _profile = new Profile();
                Contact _contact = new Contact();
                ContactDB _contactdb = new ContactDB();
                _contact = _contactdb.GetContact(_useraccount.CEID);
                _profile = _profiledb.GetProfile(_useraccount.CEID);

                if (txtMobileNo.GetPhoneNo() == _contact.Mobile)
                {
                    if (DateTime.Compare(_profile.DOB, usrDOB.GetDate()) == 0)
                    {
                        
                        GetUserInformation(_useraccount);
                    }
                }

                if (Session[CE.Global.General.UserId] == null)
                {
                    //divNewErrorMessage.Visible = true;
                    lblCarInsProfileMessage.Text = "Email address is already registered.";

                    lblAccountMessage.Text = "Your email is registered on CompareXpress. Please confirm and enter password below.";
                    txtExEmail.Text = txtEmailAddress.Text;
                    txtExEmail.ReadOnly = true;

                    mpePassword.Show();
                }
                else
                {
                    lblAutoLoginStatus.Text = "1";
                }
            }
            else
            {
                divNewErrorMessage.Visible = false; ;
                lblAccountMessage.Text = "";
                RegisterUser();
            }


            if (Session[General.UserId] != null)
            {
                if (UpdateProfile(Convert.ToInt64(Session[General.UserId].ToString())))
                {
                    //Response.Redirect("results.aspx?sortby=0");
                }
            }

            if (!SaveCarAndPolicy())
            {
                divNewErrorMessage.Visible = true;
                lblCarInsProfileMessage.Text = "Saving failed car and policy details. Please try again later.";
            }

            if (Session[CE.Global.General.UserId] != null && Session[CE.Global.General.CarId] != null)
            {
                MyDatabase _db = new MyDatabase();
                _db.ExecuteNonSqlStatement("Update tblUserResult SET IsDelete = 1 WHERE ID1 = " + Session[CE.Global.General.CarId].ToString() + " AND ID2 = " + Session[CE.Global.General.CarPolicyId].ToString() + " And ResultType = 'CI'");

                //select top 10 * from tblUserResult Where ID1 = 3253 And ResultType = 'CI'

                txtFullName.Text = General.ClearScriptTag(txtFullName.Text);
                txtVehicleNo.Text = General.ClearScriptTag(txtVehicleNo.Text);

                string _filePath = "";
                string _fileName = "";
                _filePath = GetFilePath();
                _fileName = Session[General.CarId].ToString() + "_" + CE.Global.General.GetUTCDateTime().ToString("yyyyMMMdd") + ".xls";

                Int64 _result = 0;
                ReferenceUser _referenceuser = new ReferenceUser();
                ReferenceUserDB _referenceuserdb = new ReferenceUserDB();

                txtFullName.Text = General.ClearScriptTag(txtFullName.Text);
                txtFullName.Text = Server.HtmlEncode(txtFullName.Text);

                txtEmailAddress.Text = General.ClearScriptTag(txtEmailAddress.Text);
                txtEmailAddress.Text = Server.HtmlEncode(txtEmailAddress.Text);

                txtVehicleNo.Text = General.ClearScriptTag(txtVehicleNo.Text);
                txtVehicleNo.Text = Server.HtmlEncode(txtVehicleNo.Text);

                _referenceuser.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
                _referenceuser.ProductType = "CI";
                _referenceuser.ProductId = Convert.ToInt64(Session[General.CarId].ToString());
                _referenceuser.FullName = txtFullName.Text.Trim();
                _referenceuser.NRIC = ddlIdNumber.GetIdNumber();
                _referenceuser.VehicleNumber = txtVehicleNo.Text.Trim();
                _referenceuser.MobileNumber = txtMobileNo.GetPhoneNo();
                _referenceuser.Email = txtEmailAddress.Text.Trim();
                _referenceuser.Info1 = _filePath + _fileName;
                _referenceuser.ProviderCoverTypeId = Convert.ToInt64(ddlNoMatchCoverType.Text);

                if (ddlNoMatchCoverType.SelectedValue == "1")
                {
                    _referenceuser.Info2 = ddlComprehensiveDetails.Text;
                }
                else
                {
                    _referenceuser.Info2 = "";
                }

                _referenceuser.Info3 = ddlImportant.Text;

                _referenceuser.AgentId = 0;
                _referenceuser.Status = true;
                _result = _referenceuserdb.Insert(_referenceuser);

                if (_result > 0)
                {
                    //other details
                    Int64 _detailsresult = 0;
                    ReferenceUserOtherDetails _referenceuserothers = new ReferenceUserOtherDetails();
                    ReferenceUserOtherDetailsDB _referenceuserothersdb = new ReferenceUserOtherDetailsDB();

                    _referenceuserothers.UserId = _result;
                    _referenceuserothers.CeCarId = _referenceuser.ProductId;
                    _referenceuserothers.IsParallelImport = rdoParallelImportYes.Checked;
                    _referenceuserothers.IsCNGVehicle = rdoCNGVehicleYes.Checked;
                    _referenceuserothers.IsHybridModel = rdoHybridModelYes.Checked;
                    _referenceuserothers.DrivingLicensePassDate = usrDrivingLicenseDate.GetDate();

                    if (Convert.ToInt32(ddlNoOfClaim.Text) > 0)
                    {


                        if (divClaim1.Visible)
                        {
                            _referenceuserothers.NOCLast1 = 1;
                            _referenceuserothers.NOCLast1Claim1NotAtFault = "0";
                            _referenceuserothers.NOCLast1Claim1AtFault = "0";
                            _referenceuserothers.NOCLast1Claim1Windscreen = "0";
                            _referenceuserothers.NOCLast1Claim1AccidentDate = usrClaim1AccidentDate.GetDate();
                        }

                        if (divClaim2.Visible)
                        {
                            _referenceuserothers.NOCLast2 = 1;
                            _referenceuserothers.NOCLast2Claim1NotAtFault = "0";
                            _referenceuserothers.NOCLast2Claim1AtFault = "0";
                            _referenceuserothers.NOCLast2Claim1Windscreen = "0";
                            _referenceuserothers.NOCLast2Claim1AccidentDate = usrClaim2AccidentDate.GetDate();
                        }

                        if (divClaim3.Visible)
                        {
                            _referenceuserothers.NOCLast3 = 1;
                            _referenceuserothers.NOCLast3Claim1NotAtFault = "0";
                            _referenceuserothers.NOCLast3Claim1AtFault = "0";
                            _referenceuserothers.NOCLast3Claim1Windscreen = "0";
                            _referenceuserothers.NOCLast3Claim1AccidentDate = usrClaim3AccidentDate.GetDate();
                        }

                        //if (divClaim4.Visible)
                        //{
                        //    _referenceuserothers.NOCLast2Claim1NotAtFault = "-";
                        //    _referenceuserothers.NOCLast2Claim1AtFault = "-";
                        //    _referenceuserothers.NOCLast2Claim1Windscreen = "-";
                        //    _referenceuserothers.NOCLast2Claim1AccidentDate = usrClaim4AccidentDate.GetDate();
                        //}

                        //if (divClaim5.Visible)
                        //{
                        //    _referenceuserothers.NOCLast2Claim2NotAtFault = "-";
                        //    _referenceuserothers.NOCLast2Claim2AtFault = "-";
                        //    _referenceuserothers.NOCLast2Claim2Windscreen = "-";
                        //    _referenceuserothers.NOCLast2Claim2AccidentDate = usrClaim5AccidentDate.GetDate();
                        //}
                    }
                    else
                    {
                        _referenceuserothers.NOCLast1 = 0;
                    }

                    _referenceuserothers.SuspensionOfLicense = rdoSuspensionYes.Checked;
                    _referenceuserothers.PolicyCancelled = rdoCancelledYes.Checked;

                    _referenceuserothers.RenewalQuoteReceived = Convert.ToSingle(txtRenewalQuoteReceived.Text);

                    if (Convert.ToInt32(ddlDriverCount.Text) > 0)
                    {
                        _referenceuserothers.AddDriver = true;
                    }
                    else
                    {
                        _referenceuserothers.AddDriver = false;
                    }

                    if (divDriver1.Visible)
                    {
                        _referenceuserothers.Driver1Relation = General.ClearScriptTag(txtDriver1Relation.Text.Trim());
                        _referenceuserothers.Driver1Name = General.ClearScriptTag(txtDriver1FullName.Text.Trim());
                        _referenceuserothers.Driver1NRIC = usrDriver1NRIC.GetIdNumber();
                        _referenceuserothers.Driver1LicensePassDate = usrDriver1LicensePassDate.GetDate();
                    }

                    if (divDriver2.Visible)
                    {
                        _referenceuserothers.Driver2Relation = General.ClearScriptTag(txtDriver2Relation.Text.Trim());
                        _referenceuserothers.Driver2Name = General.ClearScriptTag(txtDriver2FullName.Text.Trim());
                        _referenceuserothers.Driver2NRIC = usrDriver2NRIC.GetIdNumber();
                        _referenceuserothers.Driver2LicensePassDate = usrDriver2LicensePassDate.GetDate();
                    }

                    if (divDriver3.Visible)
                    {
                        _referenceuserothers.Driver3Relation = General.ClearScriptTag(txtDriver3Relation.Text.Trim());
                        _referenceuserothers.Driver3Name = General.ClearScriptTag(txtDriver3FullName.Text.Trim());
                        _referenceuserothers.Driver3NRIC = usrDriver3NRIC.GetIdNumber();
                        _referenceuserothers.Driver3LicensePassDate = usrDriver3LicensePassDate.GetDate();
                    }

                    _referenceuserothers.ViewedDetailId = 0;
                    _referenceuserothers.Status = true;
                    _referenceuserothers.RefCEUserId = _referenceuser.RefCEUserId;

                    _detailsresult = _referenceuserothersdb.Insert(_referenceuserothers);

                    if (_detailsresult > 0)
                    {

                        GenerateExcelQuote(_filePath, _fileName);

                        CXAgent _cxagent = new CXAgent();
                        CXAgentDB _cxagentdb = new CXAgentDB();
                        Int64 _ProductId = 0;
                        Int64 _AgentId = 0;
                        Int64 _CEID = Convert.ToInt64(Session[General.UserId].ToString());
                        string _AgentName = "";
                        string _AgentEmail = "";

                        string _strOLMailLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("IsOLMailActive");
                        if (_strOLMailLive == "1" && ReferenceCEUserAlreadyExist() == 0)
                        {
                            string[] fileList = new string[1];
                            fileList[0] = _filePath + _fileName;
                            _AgentId = Convert.ToInt64(CE.Configuration.MyConfigurationManager.GetAppSettingValue("OLAgentId"));
                            _AgentName = CE.Configuration.MyConfigurationManager.GetAppSettingValue("OLAgentName");
                            _AgentEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("OLAgentEmail");

                            _ProductId = Convert.ToInt64(Session[General.CarId].ToString());
                            UpdateAgentId(_CEID, _AgentId, "CI", _ProductId);

                            string _message = "Customer Name: " + txtFullName.Text;
                            string _title = "Offline Quotes request by " + txtFullName.Text;
                            _message += "<br/><br/>Customer Email : " + txtEmailAddress.Text;
                            _message += "<br/><br/>Contact No : " + txtMobileNo.GetPhoneNo();
                            _message += "<br/><br/>Make/Model : " + ddlCarMake.SelectedItem.Text + " " + ddlCarModel.SelectedItem.Text;
                            _message += "<br/><br/>Commencement Date : " + ddlCoverageComDate.Text;
                            _message += "<br/><br/>Cover Type : " + ddlNoMatchCoverType.SelectedItem.Text;
                            _message += "<br/><br/>Agent Name : " + _AgentName;
                            if (MyMailManager.SendCXBrokerNotificationWithAttach(_AgentEmail, _title, _message, fileList))
                            {
                                UpdateNoMatchFoundSendStatus(_CEID, _ProductId, "CI");
                            }
                            General.ClearAllSession(this.Page, "ALL");
                            Response.Redirect("~/user/user-meaasge.aspx");
                        }
                        else
                        {
                            DataTable _dtCXAgent = _cxagentdb.GetCXAgentList(_CEID, "CI", 0);
                            //DataTable _dtCXAgent = _cxagentdb.GetCXAgentList("CI", 0);
                            if (_dtCXAgent != null && _dtCXAgent.Rows.Count > 0)
                            {
                                _AgentId = Convert.ToInt64(_dtCXAgent.Rows[0]["AgentId"].ToString());
                                _AgentName = _dtCXAgent.Rows[0]["AgentName"].ToString();
                                _AgentEmail = _dtCXAgent.Rows[0]["Email"].ToString();

                                _ProductId = Convert.ToInt64(Session[General.CarId].ToString());
                                _referenceuserdb.Update(_CEID, _AgentId, "CI", _ProductId);
                                //_referenceuserdb.Update(_AgentId, "CI", _ProductId);

                                //Sakthi on 27 Apr 2011 -- Start
                                string _message = "Customer Name: " + txtFullName.Text;
                                string _title = "Offline Quotes request by " + txtFullName.Text;
                                _message += "<br/><br/>Car ID : " + Session[General.CarId].ToString();
                                _message += "<br/><br/>Customer Email : " + txtEmailAddress.Text;
                                _message += "<br/><br/>Contact No : " + txtMobileNo.GetPhoneNo();
                                _message += "<br/><br/>Make/Model : " + ddlCarMake.SelectedItem.Text + " " + ddlCarModel.SelectedItem.Text;
                                _message += "<br/><br/>Commencement Date : " + ddlCoverageComDate.SelectedItem.Text;
                                _message += "<br/><br/>Cover Type : " + ddlNoMatchCoverType.SelectedItem.Text;
                                _message += "<br/><br/>Agent Name : " + _AgentName;
                                MyMailManager.SendCXBrokerNotification(_AgentEmail, _title, _message);
                                //Sakthi on 27 Apr 2011 -- End

                                if (lblAutoLoginStatus.Text == "1")
                                {
                                    General.ClearAllSession(this.Page, "LOGOUT");
                                }
                                else
                                {
                                    General.ClearAllSession(this.Page, "ALL");
                                }
                                //Response.Redirect("~/User/UserMessage.aspx?mt=UM&ec=701");
                                Response.Redirect("~/user/user-meaasge.aspx");
                            }
                        }
                    }
                }
            }
        }
    }

    public Int64 UpdateNoMatchFoundSendStatus(Int64 RefCEUserId, Int64 ProductId, string ProductType)
    {

        MyDatabase _db = new MyDatabase();
        Int64 _result = -1;
        string _spName = "[sprocCINoMatchFoundMailSendStatusUpdateSelectItem]";

        SortedList _sPara = new SortedList();

        #region Parameter
        _sPara.Add("@RefCEUserId", RefCEUserId);
        _sPara.Add("@ProductId", ProductId);
        _sPara.Add("@ProductType", ProductType);
        #endregion

        _result = _db.ExecuteSP(_spName, _sPara);

        return _result;
    }

    public Int64 ReferenceCEUserAlreadyExist()
    {
        MyDatabase _db = new MyDatabase();
        Int64 _result = -1;
        string _spName = "[sprocReferenceCEUserCheckAlreadyExist]";

        SortedList _sPara = new SortedList();
        _sPara.Add("@Status", false);

        _result = _db.ExecuteSP(_spName, _sPara);
        return _result;
    }

    public Int64 UpdateAgentId(Int64 CEID, Int64 AgentId, string ProductType, Int64 ProductId)
    {
        MyDatabase _db = new MyDatabase();
        Int64 _result = -1;
        string _spName = "sprocReferenceUserDetailUpdateOLAgentIdSingleItem";

        SortedList _sPara = new SortedList();

        #region Parameter
        _sPara.Add("@CEID", CEID);
        _sPara.Add("@AgentId", AgentId);
        _sPara.Add("@ProductType", ProductType);
        _sPara.Add("@ProductId", ProductId);
        #endregion

        _result = _db.ExecuteSP(_spName, _sPara);

        return _result;
    }

    protected void GenerateExcelQuote(string FilePath, string FileName)
    {
        Label lblContent = new Label();
        string _fileName = "FileName";

        StringBuilder strText = new StringBuilder("");
        strText.Append("<html><body><table><tr><td colspan='4'><h3>Car Insurance : Quote Request</h3></td></tr></table>");

        #region Variable Declaration

        string _html, _name, _gender, _nric, _dob, _dd, _mm, _yy, _occupation, _jobnature, _maritalstatus, _yearsofdriving, _manufactureyear, _registeryear;
        string _carmodel, _offpeek, _ncdpercent, _applicablencd, _offancedriving, _additionaldriver, _commencementdate, _email, _mobile, _vehicleno, _inscomp;
        string _drname1, _drage1, _drgender1, _drmarital1, _drocc1, _drexp1, _drjobnature1, _drname2, _drage2, _drgender2, _drmarital2, _drocc2, _drexp2, _drjobnature2;
        string _drname3, _drage3, _drgender3, _drmarital3, _drocc3, _drexp3, _drjobnature3, _drname4, _drage4, _drgender4, _drmarital4, _drocc4, _drexp4, _drjobnature4;
        string _drname5, _drage5, _drgender5, _drmarital5, _drocc5, _drexp5, _drjobnature5, _drcount, _drDOB1, _drDOB2, _drDOB3, _drDOB4, _drDOB5, _indd, _inmm, _inyy;
        string _claimstatus, _claim1ststat, _claim1stend, _claimcount1, claimamt1, _claim2ndstat, _claim2ndend, claimamt2, _claim3rdstat, _claim3rdend, claimamt3;
        string _insdate, _covertypedesc, _info2, _info3;

        string _noofclaimlast3, _claimlast3NAF1, _claimlast3AF1, _claimlast3Windscreen1, _claimlast3NAF2, _claimlast3AF2, _claimlast3Windscreen2, _claimlast3NAF3, _claimlast3AF3, _claimlast3Windscreen3;
        string _noofclaimlast2, _claimlast2NAF1, _claimlast2AF1, _claimlast2Windscreen1, _claimlast2NAF2, _claimlast2AF2, _claimlast2Windscreen2, _claimlast2NAF3, _claimlast2AF3, _claimlast2Windscreen3;
        string _noofclaimlast1, _claimlast1NAF1, _claimlast1AF1, _claimlast1Windscreen1, _claimlast1NAF2, _claimlast1AF2, _claimlast1Windscreen2, _claimlast1NAF3, _claimlast1AF3, _claimlast1Windscreen3;
        string _suspension, _policycancelled, _driver1relation, _driver2relation, _driver3relation, _driver4relation, _driver5relation, _reftableuserid;
        string _renewalquote, _driver1name, _driver1nric, _driver2name, _driver2nric;
        string _driver3name, _driver3nric, _driver4name, _driver4nric, _driver5name, _driver5nric;
        string _parallelimport, _cngvehicle, _hybridmodel;

        DateTime _ddob, _indate;
        DateTime _drddob1 = CE.Global.General.GetUTCDateTime();
        DateTime _drddob2 = CE.Global.General.GetUTCDateTime();
        DateTime _drddob3 = CE.Global.General.GetUTCDateTime();
        DateTime _drddob4 = CE.Global.General.GetUTCDateTime();
        DateTime _drddob5 = CE.Global.General.GetUTCDateTime();
        DateTime _drivinglicensepass = CE.Global.General.GetUTCDateTime();
        DateTime _claimlast3AccidentDate1 = CE.Global.General.GetUTCDateTime();
        DateTime _claimlast3AccidentDate2 = CE.Global.General.GetUTCDateTime();
        DateTime _claimlast3AccidentDate3 = CE.Global.General.GetUTCDateTime();
        DateTime _claimlast2AccidentDate1 = CE.Global.General.GetUTCDateTime();
        DateTime _claimlast2AccidentDate2 = CE.Global.General.GetUTCDateTime();
        DateTime _claimlast2AccidentDate3 = CE.Global.General.GetUTCDateTime();
        DateTime _claimlast1AccidentDate1 = CE.Global.General.GetUTCDateTime();
        DateTime _claimlast1AccidentDate2 = CE.Global.General.GetUTCDateTime();
        DateTime _claimlast1AccidentDate3 = CE.Global.General.GetUTCDateTime();

        DateTime _driver1licensepassdate = CE.Global.General.GetUTCDateTime();
        DateTime _driver2licensepassdate = CE.Global.General.GetUTCDateTime();
        DateTime _driver3licensepassdate = CE.Global.General.GetUTCDateTime();
        DateTime _driver4licensepassdate = CE.Global.General.GetUTCDateTime();
        DateTime _driver5licensepassdate = CE.Global.General.GetUTCDateTime();

        _html = ""; _name = ""; _gender = ""; _nric = ""; _dob = ""; _dd = ""; _mm = ""; _yy = ""; _occupation = ""; _jobnature = ""; _maritalstatus = "";
        _yearsofdriving = ""; _manufactureyear = ""; _registeryear = ""; _carmodel = ""; _offpeek = ""; _ncdpercent = ""; _applicablencd = "";
        _offancedriving = ""; _additionaldriver = ""; _commencementdate = ""; _email = ""; _mobile = ""; _vehicleno = ""; _inscomp = "";
        _drname1 = ""; _drage1 = ""; _drgender1 = ""; _drmarital1 = ""; _drocc1 = ""; _drexp1 = ""; _drjobnature1 = "";
        _drname2 = ""; _drage2 = ""; _drgender2 = ""; _drmarital2 = ""; _drocc2 = ""; _drexp2 = ""; _drjobnature2 = "";
        _drname3 = ""; _drage3 = ""; _drgender3 = ""; _drmarital3 = ""; _drocc3 = ""; _drexp3 = ""; _drjobnature3 = "";
        _drname4 = ""; _drage4 = ""; _drgender4 = ""; _drmarital4 = ""; _drocc4 = ""; _drexp4 = ""; _drjobnature4 = "";
        _drname5 = ""; _drage5 = ""; _drgender5 = ""; _drmarital5 = ""; _drocc5 = ""; _drexp5 = ""; _drjobnature5 = ""; _drcount = "0";
        _drDOB1 = ""; _drDOB2 = ""; _drDOB3 = ""; _drDOB4 = ""; _drDOB5 = ""; _indd = ""; _inmm = ""; _inyy = "";
        _claimstatus = ""; _claim1ststat = ""; _claim1stend = ""; _claimcount1 = ""; claimamt1 = "0"; _claim2ndstat = ""; _claim2ndend = "";
        claimamt2 = "0"; _claim3rdstat = ""; _claim3rdend = ""; claimamt3 = "0"; _covertypedesc = ""; _info2 = ""; _info3 = "";

        _noofclaimlast3 = "0"; _claimlast3NAF1 = ""; _claimlast3AF1 = ""; _claimlast3Windscreen1 = ""; _claimlast3NAF2 = ""; _claimlast3AF2 = ""; _claimlast3Windscreen2 = ""; _claimlast3NAF3 = ""; _claimlast3AF3 = ""; _claimlast3Windscreen3 = "";
        _noofclaimlast2 = "0"; _claimlast2NAF1 = ""; _claimlast2AF1 = ""; _claimlast2Windscreen1 = ""; _claimlast2NAF2 = ""; _claimlast2AF2 = ""; _claimlast2Windscreen2 = ""; _claimlast2NAF3 = ""; _claimlast2AF3 = ""; _claimlast2Windscreen3 = "";
        _noofclaimlast1 = "0"; _claimlast1NAF1 = ""; _claimlast1AF1 = ""; _claimlast1Windscreen1 = ""; _claimlast1NAF2 = ""; _claimlast1AF2 = ""; _claimlast1Windscreen2 = ""; _claimlast1NAF3 = ""; _claimlast1AF3 = ""; _claimlast1Windscreen3 = "";
        _suspension = ""; _policycancelled = ""; _driver1relation = ""; _driver2relation = ""; _driver3relation = ""; _driver4relation = ""; _driver5relation = ""; _reftableuserid = "";

        _renewalquote = ""; _driver1name = ""; _driver1nric = ""; _driver2name = ""; _driver2nric = ""; _driver3name = ""; _driver3nric = "";
        _driver4name = ""; _driver4nric = ""; _driver5name = ""; _driver5nric = "";

        _parallelimport = "No"; _cngvehicle = "No"; _hybridmodel = "No";

        #endregion
        CarInsuranceDB _carinsurancedb = new CarInsuranceDB();

        Int64 _RefId = Convert.ToInt64(Session[General.CarId].ToString());
        Int64 _UserId = Convert.ToInt64(Session[General.UserId].ToString());
        DataSet _dsNomatchFound = new DataSet();
        _dsNomatchFound = _carinsurancedb.GetCINomatchFoundQuotes(_RefId, _UserId, "CI");
        if (_dsNomatchFound.Tables[0].Rows.Count > 0)
        {
            #region variables
            _name = _dsNomatchFound.Tables[0].Rows[0]["Name"].ToString();
            _nric = _dsNomatchFound.Tables[0].Rows[0]["NRIC"].ToString();
            _manufactureyear = _dsNomatchFound.Tables[0].Rows[0]["ManufactYear"].ToString();
            _registeryear = _dsNomatchFound.Tables[0].Rows[0]["RegYear"].ToString();
            _carmodel = _dsNomatchFound.Tables[0].Rows[0]["MakeModelDesc"].ToString();
            _ddob = Convert.ToDateTime(_dsNomatchFound.Tables[0].Rows[0]["DOB"].ToString());
            _dd = _ddob.Day.ToString("00");
            _mm = _ddob.Month.ToString("00");
            _yy = _ddob.Year.ToString();
            _dob = _dd + "/" + _mm + "/" + _yy;
            //_dob = _dsNomatchFound.Tables[0].Rows[0]["DOB"].ToString();
            _maritalstatus = _dsNomatchFound.Tables[0].Rows[0]["Marital"].ToString();
            _gender = _dsNomatchFound.Tables[0].Rows[0]["Gender"].ToString();
            _jobnature = _dsNomatchFound.Tables[0].Rows[0]["JobNature"].ToString();
            _email = _dsNomatchFound.Tables[0].Rows[0]["Email"].ToString();
            _yearsofdriving = _dsNomatchFound.Tables[0].Rows[0]["YearDriveSg"].ToString();
            _occupation = _dsNomatchFound.Tables[0].Rows[0]["Description"].ToString();
            _mobile = _dsNomatchFound.Tables[0].Rows[0]["Mobile"].ToString();

            _reftableuserid = _dsNomatchFound.Tables[0].Rows[0]["UserId"].ToString();
            _covertypedesc = _dsNomatchFound.Tables[0].Rows[0]["ProviderCoverTypeDesc"].ToString();

            _info2 = _dsNomatchFound.Tables[0].Rows[0]["info2"].ToString();
            _info3 = _dsNomatchFound.Tables[0].Rows[0]["info3"].ToString();

            if (_dsNomatchFound.Tables[0].Rows[0]["IsClaimLastThreeYear"].ToString() == "0")
            {
                _claimstatus = "No";
            }
            else
            {
                _claimstatus = "Yes";
            }
            _ncdpercent = _dsNomatchFound.Tables[0].Rows[0]["NCDPercent"].ToString();
            if (_ncdpercent.ToString() == "-1")
            {
                _ncdpercent = "No NCD(First Policy)";
            }
            else
            {
                _ncdpercent += "%";
            }
            _applicablencd = _dsNomatchFound.Tables[0].Rows[0]["ApplicableNCD"].ToString();
            _additionaldriver = _dsNomatchFound.Tables[0].Rows[0]["AddDriver"].ToString();
            _offpeek = _dsNomatchFound.Tables[0].Rows[0]["Offbeak"].ToString();
            _offancedriving = _dsNomatchFound.Tables[0].Rows[0]["IsOffDriveCom"].ToString();
            _drcount = _dsNomatchFound.Tables[0].Rows[0]["NoOfDriver"].ToString();
            if (_dsNomatchFound.Tables[1].Rows.Count > 0)
            {
                _claimstatus = "Yes";
                _claim1ststat = _dsNomatchFound.Tables[1].Rows[0]["Claim1stStartDate"].ToString();
                _claim1stend = _dsNomatchFound.Tables[1].Rows[0]["Claim1stEndDate"].ToString();
                claimamt1 = _dsNomatchFound.Tables[1].Rows[0]["NOCLast1Value"].ToString();
                _claimcount1 = _dsNomatchFound.Tables[1].Rows[0]["NOCLast1"].ToString();

                _claim2ndstat = _dsNomatchFound.Tables[1].Rows[0]["Claim2ndStartDate"].ToString();
                _claim2ndend = _dsNomatchFound.Tables[1].Rows[0]["Claim2ndEndDate"].ToString();
                claimamt2 = _dsNomatchFound.Tables[1].Rows[0]["NOCLast2Value"].ToString();

                _claim3rdstat = _dsNomatchFound.Tables[1].Rows[0]["Claim3rdStartDate"].ToString();
                _claim3rdend = _dsNomatchFound.Tables[1].Rows[0]["Claim3rdEndDate"].ToString();
                claimamt3 = _dsNomatchFound.Tables[1].Rows[0]["NOCLast3Value"].ToString();
            }
            else
            {
                _claim1ststat = "";
                _claim1stend = "";
                claimamt1 = "";
                _claimcount1 = "0";

                _claim2ndstat = "";
                _claim2ndend = "";
                claimamt2 = "";

                _claim3rdstat = "";
                _claim3rdend = "";
                claimamt3 = "";
                _claimstatus = "No";
            }


            _vehicleno = _dsNomatchFound.Tables[0].Rows[0]["VehicleNumber"].ToString();
            _indate = Convert.ToDateTime(_dsNomatchFound.Tables[0].Rows[0]["CoverageCommenceDate"].ToString());
            _indd = _indate.Day.ToString("00");
            _inmm = _indate.Month.ToString("00");
            _inyy = _indate.Year.ToString();
            _insdate = _indd + "/" + _inmm + "/" + _inyy;
            if (_dsNomatchFound.Tables[2].Rows.Count > 0)
            {
                _inscomp = _dsNomatchFound.Tables[2].Rows[0]["InsCompanyName"].ToString();
            }
            if (_dsNomatchFound.Tables[3].Rows.Count > 0)
            {
                if (Convert.ToInt16(_drcount) > 0)
                {
                    _drage1 = _dsNomatchFound.Tables[3].Rows[0]["Age"].ToString();
                    _drgender1 = _dsNomatchFound.Tables[3].Rows[0]["Gender"].ToString();
                    _drmarital1 = _dsNomatchFound.Tables[3].Rows[0]["Marital"].ToString();
                    _drocc1 = _dsNomatchFound.Tables[3].Rows[0]["Description"].ToString();
                    _drexp1 = _dsNomatchFound.Tables[3].Rows[0]["YearOfDrivingInSg"].ToString();
                    _drDOB1 = _dsNomatchFound.Tables[3].Rows[0]["DOB"].ToString();
                    //_drddob1 = Convert.ToDateTime(_dsNomatchFound.Tables[3].Rows[0]["DOB"].ToString());
                    _drjobnature1 = _dsNomatchFound.Tables[3].Rows[0]["JobNature"].ToString();
                }
                if (Convert.ToInt16(_drcount) > 1)
                {
                    _drage2 = _dsNomatchFound.Tables[3].Rows[1]["Age"].ToString();
                    _drgender2 = _dsNomatchFound.Tables[3].Rows[1]["Gender"].ToString();
                    _drmarital2 = _dsNomatchFound.Tables[3].Rows[1]["Marital"].ToString();
                    _drocc2 = _dsNomatchFound.Tables[3].Rows[1]["Description"].ToString();
                    _drexp2 = _dsNomatchFound.Tables[3].Rows[1]["YearOfDrivingInSg"].ToString();
                    _drDOB2 = _dsNomatchFound.Tables[3].Rows[1]["DOB"].ToString();
                    //_drddob2 = Convert.ToDateTime(_dsNomatchFound.Tables[3].Rows[1]["DOB"].ToString());
                    _drjobnature2 = _dsNomatchFound.Tables[3].Rows[1]["JobNature"].ToString();
                }
                if (Convert.ToInt16(_drcount) > 2)
                {
                    _drage3 = _dsNomatchFound.Tables[3].Rows[2]["Age"].ToString();
                    _drgender3 = _dsNomatchFound.Tables[3].Rows[2]["Gender"].ToString();
                    _drmarital3 = _dsNomatchFound.Tables[3].Rows[2]["Marital"].ToString();
                    _drocc3 = _dsNomatchFound.Tables[3].Rows[2]["Description"].ToString();
                    _drexp3 = _dsNomatchFound.Tables[3].Rows[2]["YearOfDrivingInSg"].ToString();
                    _drDOB3 = _dsNomatchFound.Tables[3].Rows[2]["DOB"].ToString();
                    //_drddob3 = Convert.ToDateTime(_dsNomatchFound.Tables[3].Rows[2]["DOB"].ToString());
                    _drjobnature3 = _dsNomatchFound.Tables[3].Rows[2]["JobNature"].ToString();
                }
                if (Convert.ToInt16(_drcount) > 3)
                {
                    _drage4 = _dsNomatchFound.Tables[3].Rows[3]["Age"].ToString();
                    _drgender4 = _dsNomatchFound.Tables[3].Rows[3]["Gender"].ToString();
                    _drmarital4 = _dsNomatchFound.Tables[3].Rows[3]["Marital"].ToString();
                    _drocc4 = _dsNomatchFound.Tables[3].Rows[3]["Description"].ToString();
                    _drexp4 = _dsNomatchFound.Tables[3].Rows[3]["YearOfDrivingInSg"].ToString();
                    _drDOB4 = _dsNomatchFound.Tables[3].Rows[3]["DOB"].ToString();
                    //_drddob4 = Convert.ToDateTime(_dsNomatchFound.Tables[3].Rows[3]["DOB"].ToString());
                    _drjobnature4 = _dsNomatchFound.Tables[3].Rows[3]["JobNature"].ToString();
                }
                if (Convert.ToInt16(_drcount) > 4)
                {
                    _drage5 = _dsNomatchFound.Tables[3].Rows[4]["Age"].ToString();
                    _drgender5 = _dsNomatchFound.Tables[3].Rows[4]["Gender"].ToString();
                    _drmarital5 = _dsNomatchFound.Tables[3].Rows[4]["Marital"].ToString();
                    _drocc5 = _dsNomatchFound.Tables[3].Rows[4]["Description"].ToString();
                    _drexp5 = _dsNomatchFound.Tables[3].Rows[4]["YearOfDrivingInSg"].ToString();
                    _drDOB5 = _dsNomatchFound.Tables[3].Rows[4]["DOB"].ToString();
                    //_drddob5 = Convert.ToDateTime(_dsNomatchFound.Tables[3].Rows[4]["DOB"].ToString());
                    _drjobnature5 = _dsNomatchFound.Tables[3].Rows[4]["JobNature"].ToString();
                }
            }

            #endregion

            #region refotherdetails variables

            ReferenceUserOtherDetails refothers = new ReferenceUserOtherDetails();
            ReferenceUserOtherDetailsDB refothersDB = new ReferenceUserOtherDetailsDB();

            refothers = refothersDB.GetReferenceUserOtherDetails(_UserId, _RefId, Convert.ToInt64(_reftableuserid));

            if (refothers != null)
            {
                if (refothers.IsParallelImport)
                {
                    _parallelimport = "Yes";
                }
                else
                {
                    _parallelimport = "No";
                }
                if (refothers.IsCNGVehicle)
                {
                    _cngvehicle = "Yes";
                }
                else
                {
                    _cngvehicle = "No";
                }
                if (refothers.IsHybridModel)
                {
                    _hybridmodel = "Yes";
                }
                else
                {
                    _hybridmodel = "No";
                }
                _drivinglicensepass = refothers.DrivingLicensePassDate;

                _noofclaimlast3 = refothers.NOCLast3.ToString();
                _claimlast3NAF1 = refothers.NOCLast3Claim1NotAtFault;
                _claimlast3AF1 = refothers.NOCLast3Claim1AtFault;
                _claimlast3Windscreen1 = refothers.NOCLast3Claim1Windscreen;
                _claimlast3AccidentDate1 = refothers.NOCLast3Claim1AccidentDate;

                _claimlast3NAF2 = refothers.NOCLast3Claim2NotAtFault;
                _claimlast3AF2 = refothers.NOCLast3Claim2AtFault;
                _claimlast3Windscreen2 = refothers.NOCLast3Claim2Windscreen;
                _claimlast3AccidentDate2 = refothers.NOCLast3Claim2AccidentDate;

                _claimlast3NAF3 = refothers.NOCLast3Claim3NotAtFault;
                _claimlast3AF3 = refothers.NOCLast3Claim3AtFault;
                _claimlast3Windscreen3 = refothers.NOCLast3Claim3Windscreen;
                _claimlast3AccidentDate3 = refothers.NOCLast3Claim3AccidentDate;

                _noofclaimlast2 = refothers.NOCLast2.ToString();
                _claimlast2NAF1 = refothers.NOCLast2Claim1NotAtFault;
                _claimlast2AF1 = refothers.NOCLast2Claim1AtFault;
                _claimlast2Windscreen1 = refothers.NOCLast2Claim1Windscreen;
                _claimlast2AccidentDate1 = refothers.NOCLast2Claim1AccidentDate;

                _claimlast2NAF2 = refothers.NOCLast2Claim2NotAtFault;
                _claimlast2AF2 = refothers.NOCLast2Claim2AtFault;
                _claimlast2Windscreen2 = refothers.NOCLast2Claim2Windscreen;
                _claimlast2AccidentDate2 = refothers.NOCLast2Claim2AccidentDate;

                _claimlast2NAF3 = refothers.NOCLast2Claim3NotAtFault;
                _claimlast2AF3 = refothers.NOCLast2Claim3AtFault;
                _claimlast2Windscreen3 = refothers.NOCLast2Claim3Windscreen;
                _claimlast2AccidentDate3 = refothers.NOCLast2Claim3AccidentDate;

                _noofclaimlast1 = refothers.NOCLast1.ToString();
                _claimlast1NAF1 = refothers.NOCLast1Claim1NotAtFault;
                _claimlast1AF1 = refothers.NOCLast1Claim1AtFault;
                _claimlast1Windscreen1 = refothers.NOCLast1Claim1Windscreen;
                _claimlast1AccidentDate1 = refothers.NOCLast1Claim1AccidentDate;

                _claimlast1NAF2 = refothers.NOCLast1Claim2NotAtFault;
                _claimlast1AF2 = refothers.NOCLast1Claim2AtFault;
                _claimlast1Windscreen2 = refothers.NOCLast1Claim2Windscreen;
                _claimlast1AccidentDate2 = refothers.NOCLast1Claim2AccidentDate;

                _claimlast1NAF3 = refothers.NOCLast1Claim3NotAtFault;
                _claimlast1AF3 = refothers.NOCLast1Claim3AtFault;
                _claimlast1Windscreen3 = refothers.NOCLast1Claim3Windscreen;
                _claimlast1AccidentDate3 = refothers.NOCLast1Claim3AccidentDate;

                if (refothers.SuspensionOfLicense)
                {
                    _suspension = "Yes";
                }
                else
                {
                    _suspension = "No";
                }

                if (refothers.PolicyCancelled)
                {
                    _policycancelled = "Yes";
                }
                else
                {
                    _policycancelled = "No";
                }

                _renewalquote = refothers.RenewalQuoteReceived.ToString();

                _driver1relation = refothers.Driver1Relation;
                _driver1name = refothers.Driver1Name;
                _driver1nric = refothers.Driver1NRIC;
                _driver1licensepassdate = refothers.Driver1LicensePassDate;

                _driver2relation = refothers.Driver2Relation;
                _driver2name = refothers.Driver2Name;
                _driver2nric = refothers.Driver2NRIC;
                _driver2licensepassdate = refothers.Driver2LicensePassDate;

                _driver3relation = refothers.Driver3Relation;
                _driver3name = refothers.Driver3Name;
                _driver3nric = refothers.Driver3NRIC;
                _driver3licensepassdate = refothers.Driver3LicensePassDate;

                _driver4relation = refothers.Driver4Relation;
                _driver4name = refothers.Driver4Name;
                _driver4nric = refothers.Driver4NRIC;
                _driver4licensepassdate = refothers.Driver4LicensePassDate;

                _driver5relation = refothers.Driver5Relation;
                _driver5name = refothers.Driver5Name;
                _driver5nric = refothers.Driver5NRIC;
                _driver5licensepassdate = refothers.Driver5LicensePassDate;

            }

            #endregion

            #region Html
            _html = "";

            _html += "<table style='width: 100%; background-color: white;' cellpadding='0' cellspacing='0' border='1'>"
            + "<tr>"
            + "<td width='25%' align='left'>Name</td>"
            + "<td width='25%' align='left'>" + _name.ToString() + "</td>"
            + "<td width='25%' align='left'>Date of Birth</td>"
            + "<td style='width:25%; mso-number-format: dd\\-mmm\\-yyyy' align='left'>" + _dob.ToString() + "</td>"
            + "</tr>"

            + "<tr>"
            + "<td width='25%' align='left'>Marital Status</td>"
            + "<td width='25%' align='left'>" + _maritalstatus.ToString() + "</td>"
            + "<td width='25%' align='left'>Gender</td>"
            + "<td width='25%' align='left'>" + _gender.ToString() + "</td>"
            + "</tr>"

            + "<tr>"
            + "<td width='25%' align='left'>Occupation / Business</td>"
            + "<td width='25%' align='left'>" + _occupation.ToString() + " / " + _jobnature.ToString() + "</td>"
            + "<td width='25%' align='left'>Email</td>"
            + "<td width='25%' align='left'>" + _email.ToString() + "</td>"
            + "</tr>"

            + "<tr>"
            + "<td width='25%' align='left'>Mobile No</td>"
            + "<td width='25%' align='left'>" + _mobile.ToString() + "</td>"
            + "<td width='25%' align='left'>Driving Experience</td>"
            + "<td width='25%' align='left'>" + _yearsofdriving.ToString() + "</td>"
            + "</tr>"

            + "<tr>"
            + "<td width='25%' align='left'>NRIC</td>"
            + "<td width='25%' align='left'>" + _nric.ToString() + "</td>"
            + "<td width='25%' align='left'>Commencement Date</td>"
            + "<td style='width:25%; mso-number-format: dd\\-mmm\\-yyyy' align='left'>" + _insdate.ToString() + "</td>"
            + "</tr>"

            + "<tr>"
            + "<td width='25%' align='left'>Car MakeModel</td>"
            + "<td width='25%' align='left'>" + _carmodel.ToString() + "</td>"
            + "<td width='25%' align='left'>Vehicle No</td>"
            + "<td width='25%' align='left'>" + _vehicleno.ToString() + "</td>"
            + "</tr>"

            + "<tr>"
            + "<td width='25%' align='left'>Car Manufacture Year</td>"
            + "<td width='25%' align='left'>" + _manufactureyear.ToString() + "</td>"
            + "<td width='25%' align='left'>Register Year</td>"
            + "<td width='25%' align='left'>" + _registeryear.ToString() + "</td>"
            + "</tr>"

            + "<tr>"
            + "<td width='25%' align='left'>Existing NCD</td>"
            + "<td width='25%' align='left'>" + _ncdpercent.ToString() + "</td>"
            + "<td width='25%' align='left'>NCD on next renewal (%)</td>"
            + "<td width='25%' align='left'>" + _applicablencd.ToString() + "</td>"
            + "</tr>"

            + "<tr>"
            + "<td width='25%' align='left'>Off Peak</td>"
            + "<td width='25%' align='left'>" + _offpeek.ToString() + "</td>"
            + "<td width='25%' align='left'>Offence-Free Driving</td>"
            + "<td width='25%' align='left'>" + _offancedriving.ToString() + "</td>"
            + "</tr>";

            #region Change - Sakthi on 05/Mar/2012
            /* Sakthi on 05/Mar/2012
             + "<tr>"
             + "<td width='50%'>" //Start 1
             + "<table style='width: 100%; background-color: white;' cellpadding='0' cellspacing='0' border='1'>"

             + "<tr>"
             + "<td width='50%' align='left'>Name</td>"
             + "<td width='50%' align='left'>" + _name.ToString() + "</td>"
             + "</tr>"

             + "<tr>"
             + "<td width='50%' align='left'>Marital Status</td>"
             + "<td width='50%' align='left'>" + _maritalstatus.ToString() + "</td>"
             + "</tr>"

             + "<tr>"
             + "<td width='50%' align='left'>Occupation / Business</td>"
             + "<td width='50%' align='left'>" + _occupation.ToString() + " / " + _jobnature.ToString() + "</td>"
             + "</tr>"

             + "<tr>"
             + "<td width='50%' align='left'>Mobile No</td>"
             + "<td width='50%' align='left'>" + _mobile.ToString() + "</td>"
             + "</tr>"

             + "<tr>"
             + "<td width='50%' align='left'>NRIC</td>"
             + "<td width='50%' align='left'>" + _nric.ToString() + "</td>"
             + "</tr>"

             + "<tr>"
             + "<td width='50%' align='left'>Car MakeModel</td>"
             + "<td width='50%' align='left'>" + _carmodel.ToString() + "</td>"
             + "</tr>"

             + "<tr>"
             + "<td width='50%' align='left'>Car Manufacture Year</td>"
             + "<td width='50%' align='left'>" + _manufactureyear.ToString() + "</td>"
             + "</tr>"

             + "<tr>"
             + "<td width='50%' align='left'>Existing NCD</td>"
             + "<td width='50%' align='left'>" + _ncdpercent.ToString() + "</td>"
             + "</tr>"

             + "<tr>"
             + "<td width='50%' align='left'>Off Peak</td>"
             + "<td width='50%' align='left'>" + _offpeek.ToString() + "</td>"
             + "</tr>"

             + "</table>"
             + "</td>" //End 1

             + "<td width='50%'>" //Start 2
             + "<table style='width: 100%; background-color: white;' cellpadding='0' cellspacing='0' border='1'>"

             + "<tr>"
             + "<td width='50%' align='left'>Date of Birth</td>"
             + "<td width='50%' style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _dob.ToString() + "</td>"
             + "</tr>"

             + "<tr>"
             + "<td width='50%' align='left'>Gender</td>"
             + "<td width='50%' align='left'>" + _gender.ToString() + "</td>"
             + "</tr>"

             + "<tr>"
             + "<td width='50%' align='left'>Email</td>"
             + "<td width='50%' align='left'>" + _email.ToString() + "</td>"
             + "</tr>"

             + "<tr>"
             + "<td width='50%' align='left'>Driving Experience</td>"
             + "<td width='50%' align='left'>" + _yearsofdriving.ToString() + "</td>"
             + "</tr>"

             + "<tr>"
             + "<td width='50%' align='left'>Commencement Date</td>"
             + "<td width='50%' style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _insdate.ToString() + "</td>"
             + "</tr>"

             + "<tr>"
             + "<td width='50%' align='left'>Vehicle No</td>"
             + "<td width='50%' align='left'>" + _vehicleno.ToString() + "</td>"
             + "</tr>"

             + "<tr>"
             + "<td width='50%' align='left'>Register Year</td>"
             + "<td width='50%' align='left'>" + _registeryear.ToString() + "</td>"
             + "</tr>"

             + "<tr>"
             + "<td width='50%' align='left'>NCD on next renewal (%)</td>"
             + "<td width='50%' align='left'>" + _applicablencd.ToString() + "</td>"
             + "</tr>"

             + "<tr>"
             + "<td width='50%' align='left'>Offence-Free Driving</td>"
             + "<td width='50%' align='left'>" + _offancedriving.ToString() + "</td>"
             + "</tr>"

             + "</table>"
             + "</td>" //End 2
             + "</tr>";

            _html += "</table>"; */
            #endregion

            _html += "<tr><td colspan='4' align='left'><b>Parallel Import? </b>" + _parallelimport + "</td></tr>";
            _html += "<tr><td colspan='4' align='left'><b>CNG Vehicle? </b>" + _cngvehicle + "</td></tr>";
            _html += "<tr><td colspan='4' align='left'><b>Hybrid Model? </b>" + _hybridmodel + "</td></tr>";
            _html += "<tr><td colspan='4' align='left'><b>Driving License Pass Date: </b>" + _drivinglicensepass.ToString("dd-MMM-yyyy") + "</td></tr>";
            _html += "<tr><td colspan='4' align='left'><b>Any Suspension of Driving License? </b>" + _suspension + "</td></tr>";
            _html += "<tr><td colspan='4' align='left'><b> Any motor policy cancelled or declined for renewal by insurers? </b>" + _policycancelled + "</td></tr>";
            _html += "<tr><td colspan='4' align='left'><b>Current Insurer : </b>" + _inscomp.ToString() + "</td></tr>";
            _html += "<tr><td colspan='4' align='left'><b>Cover Type : </b>" + _covertypedesc.ToString() + " " + _info2.ToString() + "</td></tr>";
            _html += "<tr><td colspan='4' align='left'><b>Renewal Quote Received : </b>S$" + _renewalquote.ToString() + "</td></tr>";
            _html += "<tr><td colspan='4' align='left'><b>Most Important to you : </b>" + _info3.ToString() + "</td></tr>";
            _html += "<tr><td colspan='4' align='left'><b>Any Claims in the Last 3 Years? : </b>" + _claimstatus.ToString() + "</td></tr>"; if (_claimstatus == "Yes")
            {
                Int16 _1YearClaim = 0;
                Int16 _2YearClaim = 0;
                Int16 _3YearClaim = 0;
                string _TotalClaim = "0";
                _1YearClaim = Convert.ToInt16(_noofclaimlast1.ToString());
                _2YearClaim = Convert.ToInt16(_noofclaimlast2.ToString());
                _3YearClaim = Convert.ToInt16(_noofclaimlast3.ToString());
                _TotalClaim = (_1YearClaim + _2YearClaim + _3YearClaim).ToString();

                double _1YearClaimAmount = 0.0;
                double _2YearClaimAmount = 0.0;
                double _3YearClaimAmount = 0.0;
                double _TotalClaimAmount = 0.0;
                _1YearClaimAmount = Convert.ToDouble(claimamt1.ToString());
                _2YearClaimAmount = Convert.ToDouble(claimamt2.ToString());
                _3YearClaimAmount = Convert.ToDouble(claimamt3.ToString());
                _TotalClaimAmount = (_1YearClaimAmount + _2YearClaimAmount + _3YearClaimAmount);

                _html += "<tr><td style='width:25%' align='left'><b>No of Claim</b></td>"
                + "<td style='width: 25%' align='left'>" + _TotalClaim.ToString() + "</td>"
                + "<td style='width: 25%' align='left'><b>Total Claim Amount</b></td>"
                + "<td style='width: 25%' align='left'>" + Server.HtmlEncode("S$" + _TotalClaimAmount.ToString("#,##0.00")) + "</td></tr>";

                if (claimamt3.ToString() != "0")
                {
                    _html += "<tr><td style='width:25%' align='left'>Accident Date</td>"
                    + "<td style='width:25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'> " + _claimlast1AccidentDate1.ToString("dd/MMM/yyyy") + "</td>"
                    + "<td style='width: 25%' align='left'> Claim Amount</td>"
                    + "<td style='width: 25%' align='left'>" + claimamt3.ToString() + "</td></tr>";
                }

                if (claimamt2.ToString() != "0")
                {
                    _html += "<tr><td style='width:25%' align='left'>Accident Date</td>"
                    + "<td style='width:25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'> " + _claimlast2AccidentDate1.ToString("dd/MMM/yyyy") + "</td>"
                    + "<td style='width: 25%' align='left'> Claim Amount</td>"
                    + "<td style='width: 25%' align='left'>" + claimamt2.ToString() + "</td></tr>";
                }

                if (claimamt1.ToString() != "0")
                {
                    _html += "<tr><td style='width:25%' align='left'>Accident Date</td>"
                    + "<td style='width:25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'> " + _claimlast3AccidentDate1.ToString("dd/MMM/yyyy") + "</td>"
                    + "<td style='width: 25%' align='left'> Claim Amount</td>"
                    + "<td style='width: 25%' align='left'>" + claimamt1.ToString() + "</td></tr>";
                }

                /* OLD CLAIM HTML
                if (claimamt1.ToString() != "0")
                {
                    _html += "<tr><td style='width:25%' align='left'>Claim Date</td>"
                    + "<td style='width:25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'> " + _claim1ststat.ToString() + " to " + _claim1stend.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'> Claim Amount</td>"
                    + "<td style='width: 25%' align='left'>" + claimamt1.ToString() + "</td></tr>";

                    if (_noofclaimlast1 == "1")
                    {
                        _html += "<tr><td align='left' colspan='4'>Claim 1</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%'  align='left'> " + _claimlast1NAF1 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast1AF1 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast1Windscreen1 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast1AccidentDate1.ToString("dd/MMM/yyyy") + "</td></tr>";

                    }

                    if (_noofclaimlast1 == "2")
                    {
                        _html += "<tr><td align='left' colspan='4'>Claim 1</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%'  align='left'> " + _claimlast1NAF1 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast1AF1 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast1Windscreen1 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast1AccidentDate1.ToString("dd/MMM/yyyy") + "</td></tr>";


                        _html += "<tr><td align='left' colspan='4'>Claim 2</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%'  align='left'> " + _claimlast1NAF2 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast1AF2 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast1Windscreen2 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast1AccidentDate2.ToString("dd/MMM/yyyy") + "</td></tr>";

                    }

                    if (_noofclaimlast1 == "3")
                    {
                        _html += "<tr><td align='left' colspan='4'>Claim 1</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%'  align='left'> " + _claimlast1NAF1 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast1AF1 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast1Windscreen1 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast1AccidentDate1.ToString("dd/MMM/yyyy") + "</td></tr>";


                        _html += "<tr><td align='left' colspan='4'>Claim 2</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%'  align='left'> " + _claimlast1NAF2 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast1AF2 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast1Windscreen2 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast1AccidentDate2.ToString("dd/MMM/yyyy") + "</td></tr>";

                        _html += "<tr><td align='left' colspan='4'>Claim 3</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%'  align='left'> " + _claimlast1NAF3 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast1AF3 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast1Windscreen3 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast1AccidentDate3.ToString("dd/MMM/yyyy") + "</td></tr>";

                    }

                }


                if (claimamt2.ToString() != "0")
                {
                    _html += "<tr><td style='width:25%' align='left'>Claim Date</td>"
                    + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claim2ndstat.ToString() + " to " + _claim2ndend.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'> Claim Amount</td>"
                    + "<td style='width: 25%' align='left'>" + claimamt2.ToString() + "</td></tr>";

                    if (_noofclaimlast2 == "1")
                    {
                        _html += "<tr><td align='left' colspan='4'>Claim 1</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%'  align='left'> " + _claimlast2NAF1 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast2AF1 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast2Windscreen1 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast2AccidentDate1.ToString("dd/MMM/yyyy") + "</td></tr>";

                    }

                    if (_noofclaimlast2 == "2")
                    {
                        _html += "<tr><td align='left' colspan='4'>Claim 1</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%'  align='left'> " + _claimlast2NAF1 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast2AF1 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast2Windscreen1 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast2AccidentDate1.ToString("dd/MMM/yyyy") + "</td></tr>";

                        _html += "<tr><td align='left' colspan='4'>Claim 2</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%'  align='left'> " + _claimlast2NAF2 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast2AF2 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast2Windscreen2 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast2AccidentDate2.ToString("dd/MMM/yyyy") + "</td></tr>";

                    }

                    if (_noofclaimlast2 == "3")
                    {
                        _html += "<tr><td align='left' colspan='4'>Claim 1</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast2NAF1 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast2AF1 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast2Windscreen1 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast2AccidentDate1.ToString("dd/MMM/yyyy") + "</td></tr>";

                        _html += "<tr><td align='left' colspan='4'>Claim 2</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%'  align='left'> " + _claimlast2NAF2 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast2AF2 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast2Windscreen2 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast2AccidentDate2.ToString("dd/MMM/yyyy") + "</td></tr>";

                        _html += "<tr><td align='left' colspan='4'>Claim 3</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%'  align='left'> " + _claimlast2NAF3 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast2AF3 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast2Windscreen3 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast2AccidentDate3.ToString("dd/MMM/yyyy") + "</td></tr>";

                    }
                }
                if (claimamt3.ToString() != "0")
                {
                    _html += "<tr><td style='width:25%' align='left'>Claim Date</td>"
                    + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claim3rdstat.ToString() + " to " + _claim3rdend.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'> Claim Amount</td>"
                    + "<td style='width: 25%' align='left'>" + claimamt3.ToString() + "</td></tr>";

                    if (_noofclaimlast3 == "1")
                    {
                        _html += "<tr><td align='left' colspan='4'>Claim 1</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%'  align='left'> " + _claimlast3NAF1 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast3AF1 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast3Windscreen1 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast3AccidentDate1.ToString("dd/MMM/yyyy") + "</td></tr>";

                    }

                    if (_noofclaimlast3 == "2")
                    {
                        _html += "<tr><td align='left' colspan='4'>Claim 1</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%'  align='left'> " + _claimlast3NAF1 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast3AF1 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast3Windscreen1 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast3AccidentDate1.ToString("dd/MMM/yyyy") + "</td></tr>";

                        _html += "<tr><td align='left' colspan='4'>Claim 2</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast3NAF2 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast3AF2 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast3Windscreen2 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast3AccidentDate2.ToString("dd/MMM/yyyy") + "</td></tr>";

                    }

                    if (_noofclaimlast3 == "3")
                    {
                        _html += "<tr><td align='left' colspan='4'>Claim 1</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%'  align='left'> " + _claimlast3NAF1 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast3AF1 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast3Windscreen1 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast3AccidentDate1.ToString("dd/MMM/yyyy") + "</td></tr>";

                        _html += "<tr><td align='left' colspan='4'>Claim 2</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%'  align='left'> " + _claimlast3NAF2 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast3AF2 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast3Windscreen2 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast3AccidentDate2.ToString("dd/MMM/yyyy") + "</td></tr>";

                        _html += "<tr><td align='left' colspan='4'>Claim 3</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Not At Fault</td>"
                        + "<td style='width: 25%'  align='left'> " + _claimlast3NAF3 + "</td>"
                        + "<td style='width: 25%' align='left'>At Fault</td>"
                        + "<td style='width: 25%' align='left'>" + _claimlast3AF3 + "</td></tr>";

                        _html += "<tr><td style='width:25%' align='left'>Windscreen</td>"
                        + "<td style='width: 25%' align='left'> " + _claimlast3Windscreen3 + "</td>"
                        + "<td style='width: 25%' align='left'>Accident Date</td>"
                        + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claimlast3AccidentDate3.ToString("dd/MMM/yyyy") + "</td></tr>";

                    }
                }

                OLD CLAIM HTML */
            }

            _html += "<tr><td colspan='4' align='left'><b>Additional drivers : </b>" + _additionaldriver.ToString() + "</td></tr>";
            if (_additionaldriver == "Yes")
            {
                if (Convert.ToInt16(_drcount) > 0)
                {

                    _html += "<tr><td colspan='4' align='left'>Driver 1</td></tr>"
                    + "<tr><td style='width:25%' align='left'>Name</td>"
                    + "<td style='width: 25%' align='left'>" + _driver1name + "</td>"
                    + "<td style='width: 25%' align='left'>Relation </td>"
                    + "<td style='width: 25%' align='left'> " + _driver1relation + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>NRIC</td>"
                    + "<td style='width: 25%' align='left'>" + _driver1nric + "</td>"
                    + "<td style='width: 25%' align='left'>License Pass Date </td>"
                    + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'> " + _driver1licensepassdate.ToString("dd/MMM/yyyy") + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Driver DOB</td>"
                    + "<td style='width: 25%' style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _drDOB1.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Driving Experience</td>"
                    + "<td style='width: 25%' align='left'>" + _drexp1.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Gender</td>"
                    + "<td style='width: 25%' align='left'>" + _drgender1.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Marital Status</td>"
                    + "<td style='width: 25%' align='left'>" + _drmarital1.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Occupation</td>"
                    + "<td style='width: 25%' align='left'>" + _drocc1.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Job Nature</td>"
                    + "<td style='width: 25%' align='left'>" + _drjobnature1.ToString() + "</td></tr>";


                }
                if (Convert.ToInt16(_drcount) > 1)
                {
                    _html += "<tr><td colspan='4' align='left'>Driver 2</td></tr>"
                    + "<tr><td style='width:25%' align='left'>Name</td>"
                    + "<td style='width: 25%' align='left'>" + _driver2name + "</td>"
                    + "<td style='width: 25%' align='left'>Relation </td>"
                    + "<td style='width: 25%' align='left'> " + _driver2relation + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>NRIC</td>"
                    + "<td style='width: 25%' align='left'>" + _driver2nric + "</td>"
                    + "<td style='width: 25%' align='left'>License Pass Date </td>"
                    + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'> " + _driver2licensepassdate.ToString("dd/MMM/yyyy") + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Driver DOB</td>"
                    + "<td style='width: 25%' style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _drDOB2.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Driving Experience</td>"
                    + "<td style='width: 25%' align='left'>" + _drexp2.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Gender</td>"
                    + "<td style='width: 25%' align='left'>" + _drgender2.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Marital Status</td>"
                    + "<td style='width: 25%' align='left'>" + _drmarital2.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Occupation</td>"
                    + "<td style='width: 25%' align='left'>" + _drocc2.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Job Nature</td>"
                    + "<td style='width: 25%' align='left'>" + _drjobnature2.ToString() + "</td></tr>";
                }
                if (Convert.ToInt16(_drcount) > 2)
                {
                    _html += "<tr><td colspan='4' align='left'>Driver 3</td></tr>"
                    + "<tr><td style='width:25%' align='left'>Name</td>"
                    + "<td style='width: 25%' align='left'>" + _driver3name + "</td>"
                    + "<td style='width: 25%' align='left'>Relation </td>"
                    + "<td style='width: 25%' align='left'> " + _driver3relation + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>NRIC</td>"
                    + "<td style='width: 25%' align='left'>" + _driver3nric + "</td>"
                    + "<td style='width: 25%' align='left'>License Pass Date </td>"
                    + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'> " + _driver3licensepassdate.ToString("dd/MMM/yyyy") + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Driver DOB</td>"
                    + "<td style='width: 25%' style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _drDOB3.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Driving Experience</td>"
                    + "<td style='width: 25%' align='left'>" + _drexp3.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Gender</td>"
                    + "<td style='width: 25%' align='left'>" + _drgender3.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Marital Status</td>"
                    + "<td style='width: 25%' align='left'>" + _drmarital3.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Occupation</td>"
                    + "<td style='width: 25%' align='left'>" + _drocc3.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Job Nature</td>"
                    + "<td style='width: 25%' align='left'>" + _drjobnature3.ToString() + "</td></tr>";
                }
                if (Convert.ToInt16(_drcount) > 3)
                {
                    _html += "<tr><td colspan='4' align='left'>Driver 4</td></tr>"
                    + "<tr><td style='width:25%' align='left'>Name</td>"
                    + "<td style='width: 25%' align='left'>" + _driver4name + "</td>"
                    + "<td style='width: 25%' align='left'>Relation </td>"
                    + "<td style='width: 25%' align='left'> " + _driver4relation + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>NRIC</td>"
                    + "<td style='width: 25%' align='left'>" + _driver4nric + "</td>"
                    + "<td style='width: 25%' align='left'>License Pass Date </td>"
                    + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'> " + _driver4licensepassdate.ToString("dd/MMM/yyyy") + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Driver DOB</td>"
                    + "<td style='width: 25%' style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _drDOB4 + "</td>"
                    + "<td style='width: 25%' align='left'>Driving Experience</td>"
                    + "<td style='width: 25%' align='left'>" + _drexp4.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Gender</td>"
                    + "<td style='width: 25%' align='left'>" + _drgender4.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Marital Status</td>"
                    + "<td style='width: 25%' align='left'>" + _drmarital4.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Occupation</td>"
                    + "<td style='width: 25%' align='left'>" + _drocc4.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Job Nature</td>"
                    + "<td style='width: 25%' align='left'>" + _drjobnature4.ToString() + "</td></tr>";
                }
                if (Convert.ToInt16(_drcount) > 4)
                {
                    _html += "<tr><td colspan='4' align='left'>Driver 5</td></tr>"
                    + "<tr><td style='width:25%' align='left'>Name</td>"
                    + "<td style='width: 25%' align='left'>" + _driver5name + "</td>"
                    + "<td style='width: 25%' align='left'>Relation </td>"
                    + "<td style='width: 25%' align='left'> " + _driver5relation + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>NRIC</td>"
                    + "<td style='width: 25%' align='left'>" + _driver5nric + "</td>"
                    + "<td style='width: 25%' align='left'>License Pass Date </td>"
                    + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'> " + _driver5licensepassdate.ToString("dd/MMM/yyyy") + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Driver DOB</td>"
                    + "<td style='width: 25%' style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _drDOB5 + "</td>"
                    + "<td style='width: 25%' align='left'>Driving Experience</td>"
                    + "<td style='width: 25%' align='left'>" + _drexp5.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Gender</td>"
                    + "<td style='width: 25%' align='left'>" + _drgender5.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Marital Status</td>"
                    + "<td style='width: 25%' align='left'>" + _drmarital5.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Occupation</td>"
                    + "<td style='width: 25%' align='left'>" + _drocc5.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Job Nature</td>"
                    + "<td style='width: 25%' align='left'>" + _drjobnature5.ToString() + "</td></tr>";
                }
            }
            _html += "</table>";
            _html += "</body></html>";
            #endregion

            lblContent.Text = _html;
            MyIO myio = new MyIO();
            //_fileName = Session[General.CarId].ToString() + "_" + CE.Global.General.GetUTCDateTime().ToString("yyyyMMMdd");
            string[] filecontent = new string[1];
            filecontent[0] = strText + lblContent.Text.ToString();
            myio.WriteNewFile(FilePath, FileName, filecontent);
            //myio.WriteNewFile(GetFilePath(), _fileName + ".xls", filecontent);
            string[] filelist = new string[1];
            filelist[0] = FilePath + FileName;

            //Sakthi on 27 Jan 2011 -- Start
            //string _Email = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CINMF_TO");
            //string _CCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CINMF_CC");
            //string _BCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CINMF_BCC");

            //string convertno = General.GetRefNumber(Convert.ToInt64(Session[General.CarId].ToString()));
            //string _RefNo = "NSCI" + convertno.ToString();

            //string _strSql = "";
            //string _Date = "";
            //string _Time = "";
            //MyDatabase _db = new MyDatabase();
            //_strSql = "SELECT TOP 1 CONVERT(VARCHAR,ModifiedDate,103) AS [Date], CONVERT(VARCHAR,ModifiedDate,108) AS [Time] ";
            //_strSql += "FROM tblReferenceCEUser WHERE ProductId = " + Session[General.CarId].ToString() + "  AND ProductType = 'CI' ORDER BY ModifiedDate DESC";
            //DataTable _dtDateTime = _db.GetDataTable(_strSql);
            //if (_dtDateTime.Rows.Count > 0)
            //{
            //    _Date = _dtDateTime.Rows[0]["Date"].ToString();
            //    _Time = _dtDateTime.Rows[0]["Time"].ToString();
            //}

            //MyMailManager.SendCINoMatchFountAttachment(_Email, _CCEmail, _BCCEmail, _RefNo.ToString(), _Date, _Time, filelist);
            //Sakthi on 27 Jan 2011 -- End

        }

    }

    public void LoadNoMatchCoverType(int Year)
    {
        DataTable _dtTempCINoMatchCoverType = new DataTable();
        DataTable _dtCINoMatchCoverType = new DataTable();

        if (Year > 10)
        {
            _dtTempCINoMatchCoverType = General.GetComboItem("CINoMatchCoverType", "CXBrokerProviderId", "0", true);
            if (_dtTempCINoMatchCoverType.Rows.Count > 0)
            {
                DataSet dsCINoMatchCoverType = new DataSet();
                for (Int16 i = 0; i < _dtTempCINoMatchCoverType.Rows.Count; i++)
                {
                    if (_dtTempCINoMatchCoverType.Rows[i]["ProviderCoverTypeDesc"].ToString().ToLower() == "comprehensive")
                    {
                        dsCINoMatchCoverType = General.RemoveRow(_dtTempCINoMatchCoverType, i);
                        _dtCINoMatchCoverType = dsCINoMatchCoverType.Tables[0];
                    }
                    else
                    {
                        _dtCINoMatchCoverType = _dtTempCINoMatchCoverType;
                    }
                }
            }
        }
        else
        {
            _dtCINoMatchCoverType = General.GetComboItem("CINoMatchCoverType", "CXBrokerProviderId", "0", true);
        }
        if (_dtCINoMatchCoverType.Rows.Count > 0)
        {
            ddlNoMatchCoverType.DataSource = _dtCINoMatchCoverType;
            ddlNoMatchCoverType.DataTextField = _dtCINoMatchCoverType.Columns[0].ColumnName.ToString();
            ddlNoMatchCoverType.DataValueField = _dtCINoMatchCoverType.Columns[1].ColumnName.ToString();
            ddlNoMatchCoverType.DataBind();

            ddlNoMatchCoverType.SelectedIndex = 0;
        }


        //ddlNoMatchCoverType.Items.Insert(0, new ListItem("Select", "-1"));
    }

    protected void CheckRenewalQuote(object source, ServerValidateEventArgs args)
    {
        float iRenewalQuote = 0;

        if (txtRenewalQuoteReceived.Text != "0")
        {
            iRenewalQuote = float.Parse(txtRenewalQuoteReceived.Text);

            if (iRenewalQuote < 100 || iRenewalQuote > 30000)
            {
                args.IsValid = false;
            }
            else
            {
                args.IsValid = true;
            }
        }
        else
        {
            args.IsValid = false;
        }

    }

    protected void ddlDriverCount_SelectedIndexChanged(object sender, EventArgs e)
    {
        divDriver1.Visible = false;
        divDriver2.Visible = false;
        divDriver3.Visible = false;

        if (ddlDriverCount.Text == "1")
        {
            divDriver1.Visible = true;
        }
        else if (ddlDriverCount.Text == "2")
        {
            divDriver1.Visible = true;
            divDriver2.Visible = true;
        }
        else if (ddlDriverCount.Text == "3")
        {
            divDriver1.Visible = true;
            divDriver2.Visible = true;
            divDriver3.Visible = true;
        }

        rfvDriver1FullName.Enabled = divDriver1.Visible;
        revDriver1FullName.Enabled = divDriver1.Visible;
        rfvDriver1Relation.Enabled = divDriver1.Visible;
        rfvDriver1Gender.Enabled = divDriver1.Visible;
        usrDriver1DOB.IsEnabled = divDriver1.Visible;
        usrDriver1LicensePassDate.IsEnabled = divDriver1.Visible;
        usrDriver1NRIC.IsEnabled = divDriver1.Visible;
        rfvDriver1MaritalStatus.Enabled = divDriver1.Visible;
        rfvDriver1Occupation.Enabled = divDriver1.Visible;
        rfvDriver1JobNature.Enabled = divDriver1.Visible;

        rfvDriver2FullName.Enabled = divDriver2.Visible;
        revDriver2FullName.Enabled = divDriver2.Visible;
        rfvDriver2Relation.Enabled = divDriver2.Visible;
        rfvDriver2Gender.Enabled = divDriver2.Visible;
        usrDriver2DOB.IsEnabled = divDriver2.Visible;
        usrDriver2LicensePassDate.IsEnabled = divDriver2.Visible;
        usrDriver2NRIC.IsEnabled = divDriver2.Visible;
        rfvDriver2MaritalStatus.Enabled = divDriver2.Visible;
        rfvDriver2Occupation.Enabled = divDriver2.Visible;
        rfvDriver2JobNature.Enabled = divDriver2.Visible;

        rfvDriver3FullName.Enabled = divDriver3.Visible;
        revDriver3FullName.Enabled = divDriver3.Visible;
        rfvDriver3Relation.Enabled = divDriver3.Visible;
        rfvDriver3Gender.Enabled = divDriver3.Visible;
        usrDriver3DOB.IsEnabled = divDriver3.Visible;
        usrDriver3LicensePassDate.IsEnabled = divDriver3.Visible;
        usrDriver3NRIC.IsEnabled = divDriver3.Visible;
        rfvDriver3MaritalStatus.Enabled = divDriver3.Visible;
        rfvDriver3Occupation.Enabled = divDriver3.Visible;
        rfvDriver3JobNature.Enabled = divDriver3.Visible;
    }

    protected void ddlNoOfClaim_SelectedIndexChanged(object sender, EventArgs e)
    {
        divClaim1.Visible = false;
        divClaim2.Visible = false;
        divClaim3.Visible = false;
        divClaim4.Visible = false;
        divClaim5.Visible = false;

        if (ddlNoOfClaim.Text == "1")
        {
            divClaim1.Visible = true;
        }
        else if (ddlNoOfClaim.Text == "2")
        {
            divClaim1.Visible = true;
            divClaim2.Visible = true;
        }
        else if (ddlNoOfClaim.Text == "3")
        {
            divClaim1.Visible = true;
            divClaim2.Visible = true;
            divClaim3.Visible = true;
        }
        else if (ddlNoOfClaim.Text == "4")
        {
            divClaim1.Visible = true;
            divClaim2.Visible = true;
            divClaim3.Visible = true;
            divClaim4.Visible = true;
        }
        else if (ddlNoOfClaim.Text == "5")
        {
            divClaim1.Visible = true;
            divClaim2.Visible = true;
            divClaim3.Visible = true;
            divClaim4.Visible = true;
            divClaim5.Visible = true;
        }

        rfvClaim1Amount.Enabled = divClaim1.Visible;
        usrClaim1AccidentDate.IsEnabled = divClaim1.Visible;

        rfvClaim2Amount.Enabled = divClaim2.Visible;
        usrClaim2AccidentDate.IsEnabled = divClaim2.Visible;

        rfvClaim3Amount.Enabled = divClaim3.Visible;
        usrClaim3AccidentDate.IsEnabled = divClaim3.Visible;

        rfvClaim4Amount.Enabled = divClaim4.Visible;
        usrClaim4AccidentDate.IsEnabled = divClaim4.Visible;

        rfvClaim5Amount.Enabled = divClaim5.Visible;
        usrClaim5AccidentDate.IsEnabled = divClaim5.Visible;

    }

    protected void ddlCarMake_SelectedIndexChanged(object sender, EventArgs e)
    {
        //System.Threading.Thread.Sleep(5000);
        GenerateCarModel(Convert.ToInt32(ddlCarMake.Text), ddlCarMake.SelectedItem.Text);
    }

    private void GenerateCarModel(int CarMakeId, string CarMakeDesc)
    {
        CarDetailDB _cardeaildb = new CarDetailDB();
        DataTable _dtCarModel = new DataTable("CarTable");
        _dtCarModel = _cardeaildb.GetCarModelAndOthers(CarMakeId);
        ddlCarModel.Items.Clear();
        ddlCarModel.Items.Add(new ListItem("Select", "-1"));
        string _tempModelDesc = "";
        if (_dtCarModel != null && _dtCarModel.Rows.Count > 0)
        {
            for (int i = 0; i < _dtCarModel.Rows.Count; i++)
            {
                _tempModelDesc = _dtCarModel.Rows[i][1].ToString();
                _tempModelDesc = _tempModelDesc.Replace(CarMakeDesc, "");
                _tempModelDesc = _tempModelDesc.Trim();
                _tempModelDesc = _tempModelDesc + " " + _dtCarModel.Rows[i][2].ToString() + " " + _dtCarModel.Rows[i][3].ToString() + "cc";
                ddlCarModel.Items.Add(new ListItem(_tempModelDesc, _dtCarModel.Rows[i][0].ToString()));
            }
        }
    }

    public string GetFilePath()
    {
        string _filePath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("FileOutputPath").ToString();
        _filePath += "exceloutput\\car_nomatch\\";
        CE.InputOut.MyIO _myIO = new CE.InputOut.MyIO();
        string _todaydate = CE.Global.General.GetUTCDateTime().ToString("yyyyMMMdd");
        if (!_myIO.CheckDirectory(_filePath + _todaydate))
        {
            if (_myIO.CreateDirectory(_filePath, _todaydate))
            {
                _filePath += _todaydate + "\\";
            }
        }
        else
        {
            _filePath += _todaydate + "\\";
        }

        return _filePath;
    }

    private void RegisterUser()
    {
        Account _useraccount = new Account();
        AccountDB _useraccountdb = new AccountDB();

        Profile _userprofile = new Profile();
        ProfileDB _userprofiledb = new ProfileDB();
        Contact _contact = new Contact();
        ContactDB _contactdb = new ContactDB();

        long _result = -1;

        _useraccount.Email = txtEmailAddress.Text.ToLower();

        Random _random = new Random();
        string _authcode = "";
        //Sakthi on 21 Jan 2011
        //_authcode = "C" + _random.Next(9).ToString() + _random.Next(9).ToString() + _random.Next(9).ToString() + _random.Next(9).ToString() + _random.Next(9).ToString();
        _authcode = _random.Next(9).ToString() + _random.Next(9).ToString() + _random.Next(9).ToString() + _random.Next(9).ToString() + _random.Next(9).ToString();

        _useraccount.AuthCode = _authcode;

        _useraccount.UserId = "CEUSERAUTOOFFLINEIDCI";
        _useraccount.UserTypeId = Convert.ToInt32(CE.Global.CEUserType.Customer);
        _useraccount.IsAcceptTC = true;
        _useraccount.Status = true;
        if (Session[General.AgentId] != null)
        {
            //For Agent Create User - Phyo @28/Apr/2011
            _useraccount.RefCEUserID = Convert.ToInt64(Session[General.AgentId]);
        }
        else
        {
            _useraccount.RefCEUserID = -1;
        }
        _result = _useraccountdb.Insert(_useraccount);
        _useraccount.CEID = _result;

        if (_result > 0)
        {
            //_userprofile.Salutation = ddlSalutation.GetSalutation();

            _userprofile.FirstName = Server.HtmlEncode(txtFullName.Text.ToUpper());
            _userprofile.SurName = "";

            DateTime _dtDOB = new DateTime(1900, 1, 1);
            _userprofile.DOB = _dtDOB;

            _userprofile.DOB = usrDOB.GetDate();
            _userprofile.Gender = Convert.ToChar(ddlGender.Text);

            _userprofile.MaritalStatus = Convert.ToInt32(ddlMaritalStatus.Text);
            _userprofile.JobNature = ddlJobNature.SelectedItem.Text;
            _userprofile.Occupation = Convert.ToInt32(ddlOccupation.Text);

            _userprofile.YearDriveSg = Convert.ToInt16(ddlDrivingExpYear.Text);

            _userprofile.Status = "Complete";
            _userprofile.RefCEUserId = _useraccount.CEID;
            _result = _userprofiledb.Insert(_userprofile);

            _contact.Email = _useraccount.Email;
            _contact.Mobile = txtMobileNo.GetPhoneNo();

            _contact.Status = true;
            _contact.RefCEUserId = _useraccount.CEID;
            _result = _contactdb.Insert(_contact);

            if (_result > 0)
            {
                SaveUserLoginInformation(_useraccount.CEID, _useraccount.UserTypeId);
                Session[CE.Global.General.UserId] = _useraccount.CEID;
                Session[CE.Global.General.UserTypeId] = _useraccount.UserTypeId;
                Session[CE.Global.General.UserEmail] = _useraccount.Email;
                Session[CE.Global.General.UserPhoneNo] = _contact.Mobile;
                Session[CE.Global.General.StartTime] = CE.Global.General.GetUTCDateTime().ToString();

                if (_userprofile.FirstName != string.Empty)
                {
                    Session[CE.Global.General.UserName] = _userprofile.SurName + " " + _userprofile.FirstName;
                }
                else
                {
                    Session[CE.Global.General.UserName] = _userprofile.SurName;
                }

                //update CarIds
                Int64 _userId = Convert.ToInt64(Session[General.UserId].ToString());
                Int64 _carId = Convert.ToInt64(Session[General.CarId].ToString());

                CarDetailDB cardb = new CarDetailDB();
                cardb.UpdateCarDetailPolicy(_carId, _userId);

                Session[CE.Global.General.UserProfileAndContactComplete] = "1";

                //START Stop Welcome message @ 20/Dec/2011 - PHYO
                //string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("IsCXLive");
                //if (_strCXLive != "")
                //{
                //    if (!SendMailToUser(_authcode))
                //    {
                //        //Email Can't be sent
                //        _useraccount.Info1 = "0";
                //        _useraccount.Info2 = "New User - Car Insurance";
                //        _result = _useraccountdb.Insert(_useraccount);

                //    }
                //}
                //END Stop Welcome message @ 20/Dec/2011 - PHYO

                //Response.Redirect("results.aspx?sortby=" + ddlSortBy.Text);
                //Response.Redirect("results.aspx?sortby=0");
                //Response.Redirect("results-new.aspx?sortby=0");

            }
        }
    }

    private bool UpdateProfile(Int64 UserId)
    {
        _profile = new CE.User.Profile();
        _profiledb = new ProfileDB();

        _contact = new Contact();
        _contactdb = new ContactDB();
        Int64 _userId = UserId;

        _profile = _profiledb.GetProfile(_userId);
        _contact = _contactdb.GetContact(_userId);
        bool _result = true;

        if (_profile != null)
        {
            long _resultUpdate = 0;

            _profile.FirstName = "";
            _profile.SurName = txtFullName.Text;
            _profile.DOB = usrDOB.GetDate();
            _profile.Gender = Convert.ToChar(ddlGender.Text);

            _profile.MaritalStatus = Convert.ToInt32(ddlMaritalStatus.Text);
            _profile.JobNature = ddlJobNature.SelectedItem.Text;
            _profile.Occupation = Convert.ToInt32(ddlOccupation.Text);
            _profile.YearDriveSg = Convert.ToInt16(ddlDrivingExpYear.Text);
            _profile.Status = "Complete";

            _resultUpdate = _profiledb.Insert(_profile);

            if (_contact != null)
            {
                _contact.Mobile = txtMobileNo.GetPhoneNo();
                _contact.Status = true;

                _resultUpdate = _contactdb.Insert(_contact);
            }

            if (_resultUpdate <= 0)
            {
                _result = false;
            }
            else
            {
                if (_profile.FirstName != string.Empty)
                {
                    Session[CE.Global.General.UserName] = _profile.SurName + " " + _profile.FirstName;
                }
                else
                {
                    Session[CE.Global.General.UserName] = _profile.SurName;
                }
                Session[General.UserPhoneNo] = txtMobileNo.GetPhoneNo();
                Session[CE.Global.General.UserProfileAndContactComplete] = "1";
                if (Convert.ToInt32(Session[CE.Global.General.UserTypeId]) ==
                    Convert.ToInt32(CE.Global.CEUserType.Provider))
                {
                    Session[CE.Global.General.ProviderProfileFirstTime] = "0";
                }
            }
        }
        else
        {
            divNewErrorMessage.Visible = true;
            lblCarInsProfileMessage.Text = "Failed to update profile. Please try again later.";
        }

        _profile = null;
        _contact = null;

        return _result;
    }

    protected bool SaveUserLoginInformation(Int64 CEID, int UserTypeId)
    {
        LoginHistory _loghis = new LoginHistory();
        LoginHistoryDB _loghisdb = new LoginHistoryDB();
        LoginInformation _loginfo = new LoginInformation();
        LoginInformationDB _loginfodb = new LoginInformationDB();

        _loghis.CEID = CEID;
        _loghis.UserTypeId = UserTypeId;
        _loghis.StartTime = CE.Global.General.GetUTCDateTime();
        _loghis.EndTime = CE.Global.General.GetUTCDateTime();
        _loghis.IsExpired = false;
        _loghis.Status = "LOGIN";

        _loghis.LoginHisId = _loghisdb.Insert(_loghis);

        if (_loghis.LoginHisId > 0)
        {
            Session[CE.Global.General.LoginHistoryId] = _loghis.LoginHisId.ToString();
            _loginfo.CEID = CEID;
            _loginfo.UserTypeId = UserTypeId;
            _loginfo.LogHisId = _loghis.LoginHisId;

            _loginfo.Browser = Request.Browser.Browser;
            _loginfo.BrowserType = Request.Browser.Type;
            _loginfo.BrowserVersion = Request.Browser.Version;
            _loginfo.MajorVersion = Request.Browser.MajorVersion.ToString();
            _loginfo.MinorVersion = Request.Browser.MinorVersionString;

            _loginfo.JavaScript = Request.Browser.JavaScript;
            _loginfo.VBScript = Request.Browser.VBScript;
            _loginfo.ActivX = Request.Browser.ActiveXControls;
            _loginfo.Frames = Request.Browser.Frames;
            _loginfo.Tables = Request.Browser.Tables;
            _loginfo.Cookies = Request.Browser.Cookies;
            _loginfo.DotNetVersion = Request.Browser.ClrVersion.ToString();
            _loginfo.JavaApplet = Request.Browser.JavaApplets;

            _loginfo.Win16 = Request.Browser.Win16;
            _loginfo.Win32 = Request.Browser.Win32;
            _loginfo.Platform = Request.Browser.Platform;
            _loginfo.UserAgent = Request.UserAgent.ToString();
            _loginfo.IpAddress = Request.UserHostAddress;
            _loginfo.HostName = Request.UserHostName;

            //_loginfo.Info1 = Request.Browser.Tables;
            //_loginfo.Info2 = Request.Browser.Platform;
            _loginfo.UserInfoId = _loginfodb.Insert(_loginfo);
        }

        return _loginfo.UserInfoId > 0;

    }

    protected void btnExUserLogin_Click(object sender, EventArgs e)
    {
        if (AutoLogin(100))
        {
            Int64 _userId = 0;

            if (Session[General.UserId] != null)
            {
                _userId = Convert.ToInt64(Session[General.UserId].ToString());

            }

            //Int64 _carId = 0;

            //if (Session[General.CarId] != null)
            //{
            //    _carId = Convert.ToInt64(Session[General.CarId].ToString());
            //}
            //else
            //{
            //    //Response.Redirect("carandpolicy_details.aspx");
            //    Response.Redirect("~/car-insurance/");
            //}

            if (_userId > 0)
            {
                //update CarIds
                //CarDetailDB cardb = new CarDetailDB();
                //cardb.UpdateCarDetailPolicy(_carId, _userId);

                //ibtNext.Enabled = true;
                //divPassword.Visible = false;
                //vsCarProfile.Visible = false;
                divNewErrorMessage.Visible = false;

                mpePassword.Hide();
                //divExisting.Visible = false;
                spanExistingUser.Visible = false;

                //ShowCustomerDetail(_userId);

                inputLoginCount.Value = "0";


                ShowCustomerDetail(_userId);

                //Response.Redirect("car-insurance-request.aspx");

            }
        }
        else
        {

            Int32 logincount = Convert.ToInt32(inputLoginCount.Value.Trim());
            inputLoginCount.Value = (logincount + 1).ToString();

            if (logincount >= 3)
            {
                this.btnPasswordClose_Click(this, null);
            }
            else
            {

                mpePassword.Show();
            }
        }

    }

    protected void btnPasswordClose_Click(object sender, EventArgs e)
    {
        inputLoginCount.Value = "0";
        //Response.Redirect("carandpolicy_details.aspx");
        //Response.Redirect("~/car-insurance/");
    }

    private void GetUserInformation(Account _account)
    {
        DateTime dtNow = new DateTime();
        dtNow = CE.Global.General.GetUTCDateTime();
        Session[CE.Global.General.UserId] = _account.CEID;
        Session[CE.Global.General.UserTypeId] = _account.UserTypeId;

        if (_account.UserTypeId == Convert.ToInt32(CE.Global.CEUserType.Provider))
        {
            CE.Provider.ProviderCompanyLink _comlink = new CE.Provider.ProviderCompanyLink();
            CE.Provider.ProviderCompanyLinkDB _comlinkdb = new CE.Provider.ProviderCompanyLinkDB();
            _comlink = _comlinkdb.GetProviderCompanyId(_account.CEID);
            if (_comlink != null)
            {
                Session[CE.Global.General.ProviderCompanyId] = _comlink.ProviderCompanyId;
            }
        }

        Session[CE.Global.General.UserEmail] = _account.Email;
        Session[CE.Global.General.StartTime] = dtNow.ToString();
        bool isProfileComplete = false;
        bool isContactComplete = false;

        ProfileDB _profiledb = new ProfileDB();
        Profile _profile = new Profile();
        Contact _contact = new Contact();
        ContactDB _contactdb = new ContactDB();

        _contact = _contactdb.GetContact(_account.CEID);

        _profile = _profiledb.GetProfile(_account.CEID);

        if (_contact != null)
        {
            isContactComplete = true;
            Session[CE.Global.General.UserPhoneNo] = _contact.Mobile;
        }
        else
        {
            Session[CE.Global.General.UserPhoneNo] = null;
        }

        if (_profile != null)
        {
            if (_profile.FirstName != null && _profile.FirstName != string.Empty)
            {
                Session[CE.Global.General.UserName] = Server.HtmlDecode(_profile.SurName) + " " + Server.HtmlDecode(_profile.FirstName);
            }
            else
            {
                Session[CE.Global.General.UserName] = Server.HtmlDecode(_profile.SurName);
            }

            if (!string.IsNullOrEmpty(_profile.IDType) &&
                !string.IsNullOrEmpty(_profile.IDNo) &&
                _profile.IDNo.Length == 9)
            {
                Session[CE.Global.General.UserICNumber] = _profile.IDType + " " + _profile.IDNo;
            }

            if (_profile.Status.ToLower() == "complete")
            {
                isProfileComplete = true;
            }
            else
            {
                isProfileComplete = false;
            }
        }
        else
        {
            Session[CE.Global.General.UserName] = null;
        }

        if (isProfileComplete && isContactComplete)
        {
            Session[CE.Global.General.UserProfileAndContactComplete] = "1";
        }
        else
        {
            Session[CE.Global.General.UserProfileAndContactComplete] = "0";
        }

    }

    private bool CheckUserLoginCached(string UserId)
    {
        bool _retValue = false;
        string sKey = CE.Configuration.MyConfigurationManager.GetAppSettingValue("UserCacheName");
        sKey += UserId;
        if (HttpContext.Current.Cache[sKey] == null)
        {
            _retValue = true;
        }
        else
        {
            _retValue = false;
        }
        return _retValue;
    }

    private bool AutoLogin(int LoginType)
    {
        bool isLoggedin = false;
        AccountStatus _accountstatus = new AccountStatus();
        AccountStatusDB _accountstatusdb = new AccountStatusDB();
        AccountDB _accountdb = new AccountDB();
        //Check Customer Account

        Account _account = _accountdb.GetUserAccount(txtExEmail.Text.ToLower(), Convert.ToInt32(CE.Global.CEUserType.Customer));

        if (_account != null)
        {
            if (CheckUserLoginCached(_account.CEID.ToString()))
            {
                _accountstatus = _accountstatusdb.GetAccountStatus(_account.CEID, 400);

                if (Server.HtmlDecode(txtExAuthCode.Text) == _account.AuthCode)
                {
                    if (_account.Status == true)
                    {
                        isLoggedin = true;

                        if (_account.Info1 == "0")
                        {
                            //Reset Email Fail Message
                            _account.Info1 = "";
                            _account.Info2 = "";
                            _accountdb.Insert(_account);
                        }

                        _accountstatusdb.InsertAccountStatus(_account.CEID, 400, 1);
                        lblEmailMessage.Visible = false;
                        GetUserInformation(_account);
                        SaveUserLoginInformation(_account.CEID, _account.UserTypeId);
                        CE.Global.General.CreateUpdateUserLoginCached(Page);
                        _account = null;
                        //if (LoginType == 100)
                        //{
                        //    //Response.Redirect("profile.aspx");
                        //    Response.Redirect("carAndpolicy_details.aspx");
                        //}
                        //else
                        //{
                        //    if (Session[CE.Global.General.UserProfileAndContactComplete].ToString() == "1")
                        //        Response.Redirect("~/User/ViewResultHistory.aspx?resulttitle=100");
                        //    else
                        //    {
                        //        Response.Redirect("~/User/EditProfile.aspx");
                        //    }
                        //}
                    }
                    else
                    {
                        lblEmailMessage.Visible = true;
                        lblEmailMessage.Text = "Your email has been blocked!";
                    }
                }
                else
                {
                    _accountstatusdb.InsertAccountStatus(_account.CEID, 400, 0);
                    lblEmailMessage.Visible = true;
                    lblEmailMessage.Text = "Email address or password is incorrect.";
                }
            }
            else
            {
                //Response.Redirect("UserMessage.aspx?ErrorCode=1993");
                Response.Redirect("~/user/usermessage.aspx?mt=UM&ec=1993");
            }
        }
        else
        {
            lblEmailMessage.Visible = true;
            lblEmailMessage.Text = "Email address or password is incorrect.";
        }

        return isLoggedin;
    }

    private void ShowCustomerDetail(Int64 UserId)
    {
        _profile = new CE.User.Profile();
        _profiledb = new ProfileDB();
        _contact = new Contact();
        _contactdb = new ContactDB();

        _profile = _profiledb.GetProfile(UserId);
        _profiledb = null;

        if (_profile != null)
        {

            txtFullName.Text = _profile.SurName + " " + _profile.FirstName;

            ddlMaritalStatus.Text = _profile.MaritalStatus.ToString();
            ddlOccupation.Text = _profile.Occupation.ToString();
            ddlJobNature.Text = _profile.JobNature;

            ddlGender.Text = _profile.Gender.ToString();

            usrDOB.Day = _profile.DOB.Day;
            usrDOB.Month = _profile.DOB.Month;
            usrDOB.Year = _profile.DOB.Year;

            _contact = _contactdb.GetContact(UserId);
            if (_contact != null)
            {
                txtMobileNo.PhoneNo = _contact.Mobile;
                txtEmailAddress.Text = _contact.Email;
                txtEmailAddress.ReadOnly = true;
            }

            //Disable DOB, Gender and Year of Driving Exp Sg
            //if (Session[CE.Global.General.UserTypeId].ToString() == "400")
            //{
            //    if (Session[CE.Global.General.UserProfileAndContactComplete].ToString() == "1")
            //    {
            //        usrDOB.IsEnabled = false;
            //        ddlGender.IsEnabled = false;
            //    }
            //}
            _profile = null;
        }
    }

    private bool SaveCarAndPolicy()
    {
        Int64 _carresult = 0;
        Int64 _policyresult = 0;

        CarDetail _car = new CarDetail();
        CarDetailDB _cardb = new CarDetailDB();

        ProfileDB _profiledb = new ProfileDB();
        Profile _profile = new Profile();


        Int64 _refceuserid = 0;

        if (Session[CE.Global.General.UserId] != null)
        {
            _refceuserid = Convert.ToInt64(Session[General.UserId]);
        }

        if (Session[General.CarId] != null)
        {
            _car.CECarId = Convert.ToInt64(Session[General.CarId].ToString());
            if (Session[General.AgentId] != null)
            {
                _car.Info5 = "UPDATE";
            }
        }
        else
        {
            if (Session[General.AgentId] != null)
            {
                _car.Info4 = "NEW";
            }
        }

        _car.ManufactYear = Convert.ToInt32(ddlManYear.Text);
        _car.RegYear = Convert.ToInt32(ddlRegYear.Text);

        if (Session[General.AgentId] != null)
        {
            _car.Info2 = Session[General.AgentId].ToString();
            _car.Info3 = CE.Global.General.GetUTCDateTime().ToString();
        }


        _car.CarMakeId = Convert.ToInt32(ddlCarMake.Text); //Convert.ToInt32(txtCarMakeId.Text);
        _car.CarModelId = Convert.ToInt32(ddlCarModel.Text);//Convert.ToInt32(txtCarModelId.Text);
        _car.MakeModelDesc = ddlCarMake.SelectedItem.Text + " " + ddlCarModel.SelectedItem.Text; //txtCarMakeModelDesc.Text;


        //_car.IsPeak = rdoYesOffPeak.Checked;
        if (ddlOffPeak.Text == "1")
        {
            _car.IsPeak = true;
        }
        else
        {
            _car.IsPeak = false;
        }
        _car.IsParalleImport = false;// rdoYesParallelImport.Checked;
        _car.Status = "CARREQUEST";
        _car.RefCEUserId = _refceuserid;
        _car.ViewedDetailId = 0;
        _car.CurrentStep = 1;
        _car.TotalStep = 4;

        _profile = _profiledb.GetProfile(_refceuserid);
        if (_profile != null)
        {
            //Save User Profile
            _car.Info10 = _profile.SurName.ToString();
            _car.Info11 = _profile.Gender.ToString();
            _car.Info12 = _profile.DOB.ToString("dd-MMM-yyyy");
            _car.Info13 = _profile.Occupation.ToString();
            _car.Info14 = _profile.JobNature.ToString();
            _car.Info15 = _profile.MaritalStatus.ToString();
            _car.Info16 = _profile.YearDriveSg.ToString();
        }

        _car.Info1 = ddlCurrentInsurer.Text;

        _carresult = _cardb.Insert(_car);

        _car = null;
        _cardb = null;
        _profile = null;
        _profiledb = null;

        if (_carresult > 0)
        {
            Session[CE.Global.General.CarId] = _carresult.ToString();
        }
        else
        {
            divNewErrorMessage.Visible = true;
            lblCarInsProfileMessage.Text = "Error found!";
        }
        //return _result > 0;
        if (_carresult > 0)
        {
            //CAR POLICY DETAILS
            CarPolicy _carpolicy = new CarPolicy();
            CarPolicyDB _carpolicydb = new CarPolicyDB();
            Int64 _carId = Convert.ToInt64(Session[General.CarId].ToString());


            Int64 _ceuserid = 0;

            if (Session[General.UserId] != null)
            {
                _ceuserid = Convert.ToInt64(Session[General.UserId].ToString());
            }

            Int64 _carpolicyid = 0;

            if (Session[General.CarPolicyId] != null)
            {
                _carpolicyid = Convert.ToInt64(Session[General.CarPolicyId].ToString());
                _carpolicy.CECarPolicyId = _carpolicyid;
                if (Session[General.AgentId] != null)
                {
                    _carpolicy.Info5 = "UPDATE";
                }
            }
            else
            {
                if (Session[General.AgentId] != null)
                {
                    _carpolicy.Info4 = "NEW";
                }
            }

            lblCarInsProfileMessage.Text = "";
            if (Session[General.AgentId] != null)
            {
                _carpolicy.Info2 = Session[General.AgentId].ToString();
                _carpolicy.Info3 = CE.Global.General.GetUTCDateTime().ToString();
            }
            _carpolicy.CECarId = _carId;
            _carpolicy.TypeOfCoverage = "0";
            //string strDate = ddlCoverageComDate.Text.Substring(3, 2) + "/" + ddlCoverageComDate.Text.Substring(0, 2) + "/" + ddlCoverageComDate.Text.Substring(6, 4);

            string strDate = ddlCoverageComDate.Text;
            int _iDay = Convert.ToInt32(strDate.Substring(0, 2));
            int _iMonth = Convert.ToInt32(strDate.Substring(2, 2));
            int _iYear = Convert.ToInt32(strDate.Substring(4, 4));
            _carpolicy.CoverageCommenceDate = new DateTime(_iYear, _iMonth, _iDay);


            //_carpolicy.NCDPercent = Convert.ToSingle(ddlNCD.SelectedValue);
            _carpolicy.NCDPercent = Convert.ToSingle(ddlNCD.Text);

            _carpolicy.Info1 = ddlNCD.Text;

            //if (ddlRenewNCD.Text == "60")
            //    _carpolicy.Info1 = "50";
            //else
            //    _carpolicy.Info1 = ddlRenewNCD.Text;

            //_carpolicy.Info2 = ddlNCDYear.Text;
            //_carpolicy.IsClaimLastThreeYear = rdoYesClaimLast3Year.Checked;
            if (Convert.ToInt32(ddlNoOfClaim.Text) > 0)
            {
                _carpolicy.IsClaimLastThreeYear = true;
            }
            else
            {
                _carpolicy.IsClaimLastThreeYear = false;
            }
            _carpolicy.IsInsCOE = false; // rdoYesInsCOEPARF.Checked;
            _carpolicy.IsDriveMyOrTh = false; //  rdoYesDriveMyTh.Checked;

            //carpolicy.IsOffDriveCom = rdoYesOffFDCom.Checked;
            if (ddlOffFreeDriving.Text == "1")
            {
                _carpolicy.IsOffDriveCom = true;
            }
            else
            {
                _carpolicy.IsOffDriveCom = false;
            }

            _carpolicy.TPDP = "0"; // ddlTrafficePoint.Text;
            _carpolicy.IsNCDProtection = false; // rdoYesNCDProtection.Checked;
            //_carpolicy.IsAddDriver = rdoYesAddDriver.Checked;
            if (Convert.ToInt32(ddlDriverCount.Text) > 0)
            {
                _carpolicy.IsAddDriver = true;
            }
            else
            {
                _carpolicy.IsAddDriver = false;
            }
            _carpolicy.NoOfDriver = Convert.ToInt16(ddlDriverCount.SelectedValue);
            _carpolicy.RefCEUserId = _ceuserid;
            //_carpolicy.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
            _carpolicy.Status = "SAVENEW";
            _carpolicy.CurrentStep = 2;
            _policyresult = _carpolicydb.Insert(_carpolicy);
            if (_policyresult > 0)
            {
                Session[General.CarPolicyId] = _policyresult.ToString();
                if (_carpolicy.IsClaimLastThreeYear)
                {
                    CarClaimHistory _claimhis = new CarClaimHistory();
                    CarClaimHistoryDB _claimhisdb = new CarClaimHistoryDB();

                    if (Session[General.CarClaimHistoryId] != null)
                    {
                        _claimhis = _claimhisdb.GetCarClaimHistory(Convert.ToInt64(Session[General.CarClaimHistoryId]));
                    }

                    _claimhis.CECarId = _carId;
                    _claimhis.RerCEUserId = _ceuserid;

                    if (Convert.ToInt32(ddlNoOfClaim.SelectedValue) > 0)
                    {
                        _claimhis.NoOfClaimInLast3Year = 1;
                        _claimhis.Last3YearClaimValue = txtClaim1Amount.Text;
                    }
                    else
                    {
                        _claimhis.NoOfClaimInLast3Year = 0;
                        _claimhis.Last3YearClaimValue = "0";
                    }

                    if (Convert.ToInt32(ddlNoOfClaim.SelectedValue) > 1)
                    {
                        _claimhis.NoOfClaimInLast2Year = 1;
                        _claimhis.Last2YearClaimValue = txtClaim2Amount.Text;
                    }
                    else
                    {
                        _claimhis.NoOfClaimInLast2Year = 0;
                        _claimhis.Last2YearClaimValue = "0";
                    }

                    if (Convert.ToInt32(ddlNoOfClaim.SelectedValue) > 2)
                    {
                        _claimhis.NoOfClaimInLast1Year = 1;
                        _claimhis.Last1YearClaimValue = txtClaim3Amount.Text;
                    }
                    else
                    {
                        _claimhis.NoOfClaimInLast1Year = 0;
                        _claimhis.Last1YearClaimValue = "0";
                    }
                    //_claimhis.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                    _claimhis.Status = "Active";
                    Int64 _resultclaimhis = _claimhisdb.Insert(_claimhis);
                    if (_resultclaimhis > 0)
                    {
                        Session[General.CarClaimHistoryId] = _resultclaimhis.ToString();
                        //lblMessage.Text += "Car claim history saved successfully!";
                    }
                    else
                    {
                        //lblMessage.Text += "Car claim history did not save successfully!";
                    }
                    _claimhis = null;
                    _claimhisdb = null;
                }
                else
                {
                    if (Session[General.CarClaimHistoryId] != null)
                    {
                        CarClaimHistoryDB _carclaimdb = new CarClaimHistoryDB();
                        if (_carclaimdb.UpdateStatus(Convert.ToInt64(Session[General.CarClaimHistoryId])))
                        {

                        }
                    }
                }

                //lblMessage.Text += "<br>Car policy saved successfully!";
                //lblMessage.ForeColor = System.Drawing.Color.Blue;
            }
            else
            {
                //lblMessage.Text = "Car policy did not save successfully!";
                //lblMessage.ForeColor = System.Drawing.Color.Red;
                return false;
            }

            CarDriver _cardriver = new CarDriver();
            CarDriverDB _cardriverdb = new CarDriverDB();

            if (Convert.ToInt32(ddlDriverCount.Text) > 0)
            {
                int _drivercount = Convert.ToInt32(ddlDriverCount.SelectedValue);
                int _insertcount = 0;
                _cardriverdb.UpdateAllStatus(_carId, _ceuserid);

                for (int i = 1; i <= _drivercount; i++)
                {
                    _cardriver.StepId = 1;
                    _cardriver.RerCEUserId = _ceuserid;
                    _cardriver.CECarId = _carId;
                    if (i == 1)
                    {

                        _cardriver.CarDriverId = 0;
                        //_cardriver.Salutation = UsrCarDriver1.Salutation;
                        _cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(txtDriver1FullName.Text));
                        //_cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(UsrCarDriver1.GivenName));
                        _cardriver.DOB = usrDriver1DOB.GetDate();
                        _cardriver.Gender = Convert.ToChar(ddlDriver1Gender.Text);
                        _cardriver.MaritalStatus = ddlDriver1MaritalStatus.Text;
                        _cardriver.Occupation = ddlDriver1Occupation.Text;
                        _cardriver.JobNature = ddlDriver2JobNature.Text;
                        //_cardriver.IDType = UsrCarDriver1.IDType;
                        //_cardriver.IDNo = UsrCarDriver1.IDNo;
                        //_cardriver.YearOfDrivingInSg = UsrCarDriver1.YearsOfDriving;
                        _cardriver.Status = "Active";
                    }
                    else if (i == 2)
                    {
                        _cardriver.CarDriverId = 0;
                        //_cardriver.Salutation = UsrCarDriver1.Salutation;
                        _cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(txtDriver2FullName.Text));
                        //_cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(UsrCarDriver1.GivenName));
                        _cardriver.DOB = usrDriver2DOB.GetDate();
                        _cardriver.Gender = Convert.ToChar(ddlDriver2Gender.Text);
                        _cardriver.MaritalStatus = ddlDriver2MaritalStatus.Text;
                        _cardriver.Occupation = ddlDriver2Occupation.Text;
                        _cardriver.JobNature = ddlDriver2JobNature.Text;
                        //_cardriver.IDType = UsrCarDriver1.IDType;
                        //_cardriver.IDNo = UsrCarDriver1.IDNo;
                        //_cardriver.YearOfDrivingInSg = UsrCarDriver1.YearsOfDriving;
                        _cardriver.Status = "Active";
                    }
                    else if (i == 3)
                    {
                        _cardriver.CarDriverId = 0;
                        //_cardriver.Salutation = UsrCarDriver1.Salutation;
                        _cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(txtDriver3FullName.Text));
                        //_cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(UsrCarDriver1.GivenName));
                        _cardriver.DOB = usrDriver3DOB.GetDate();
                        _cardriver.Gender = Convert.ToChar(ddlDriver3Gender.Text);
                        _cardriver.MaritalStatus = ddlDriver3MaritalStatus.Text;
                        _cardriver.Occupation = ddlDriver3Occupation.Text;
                        _cardriver.JobNature = ddlDriver3JobNature.Text;
                        //_cardriver.IDType = UsrCarDriver1.IDType;
                        //_cardriver.IDNo = UsrCarDriver1.IDNo;
                        //_cardriver.YearOfDrivingInSg = UsrCarDriver1.YearsOfDriving;
                        _cardriver.Status = "Active";
                    }

                    //_cardriver.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                    if (_cardriverdb.Insert(_cardriver) > 0)
                    {
                        _insertcount++;
                    }
                }

                _cardriverdb = null;
                _cardriver = null;

                if (_insertcount == _drivercount)
                {
                    //lblMessage.Text += "<br>All drivers are successfully saved!";
                    //lblMessage.ForeColor = System.Drawing.Color.Blue;
                }
                else
                {
                    //lblMessage.Text += "<br>All drivers are did not saved!";
                    //lblMessage.ForeColor = System.Drawing.Color.Red;
                    return false;
                }
            }
            else
            {
                _cardriverdb.UpdateAllStatus(_carId, _ceuserid);
            }

            _carpolicy = null;
            _carpolicydb = null;
        }

        if (_policyresult > 0)
        {
            //string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("IsCXLive");
            //if (_strCXLive == "1")
            //{
            //    if (CheckFirstTimeQuote())
            //    {
            //        if (!SendMailFirstQuoteToUser())
            //        {
            //            //Account _account = new Account();
            //            //AccountDB _accountdb = new AccountDB();
            //            //_account = _accountdb.GetAccount(Convert.ToInt64(Session[General.UserId].ToString()));
            //            //if (_account.Info1 == "0")
            //            //{
            //            //    _account.Info2 = "First Quote And " + _account.Info2;
            //            //}
            //            //else
            //            //{
            //            //    _account.Info1 = "0";
            //            //    _account.Info2 = "First Quote - Car Insurance";
            //            //}
            //        }
            //    }
            //}
        }
        return _policyresult > 0;
    }
}
